mirror of
https://github.com/aljazceru/CTFd.git
synced 2025-12-17 05:54:19 +01:00
* Add nested UserSchema and TeamSchema to SubmissionSchema to allow easier access to a user/team name without issuing another query/API call * Closes #2005
43 lines
1.2 KiB
Python
43 lines
1.2 KiB
Python
from marshmallow import fields
|
|
|
|
from CTFd.models import Submissions, ma
|
|
from CTFd.schemas.challenges import ChallengeSchema
|
|
from CTFd.schemas.teams import TeamSchema
|
|
from CTFd.schemas.users import UserSchema
|
|
from CTFd.utils import string_types
|
|
|
|
|
|
class SubmissionSchema(ma.ModelSchema):
|
|
challenge = fields.Nested(ChallengeSchema, only=["id", "name", "category", "value"])
|
|
user = fields.Nested(UserSchema, only=["id", "name"])
|
|
team = fields.Nested(TeamSchema, only=["id", "name"])
|
|
|
|
class Meta:
|
|
model = Submissions
|
|
include_fk = True
|
|
dump_only = ("id",)
|
|
|
|
views = {
|
|
"admin": [
|
|
"provided",
|
|
"ip",
|
|
"challenge_id",
|
|
"challenge",
|
|
"user",
|
|
"team",
|
|
"date",
|
|
"type",
|
|
"id",
|
|
],
|
|
"user": ["challenge_id", "challenge", "user", "team", "date", "type", "id"],
|
|
}
|
|
|
|
def __init__(self, view=None, *args, **kwargs):
|
|
if view:
|
|
if isinstance(view, string_types):
|
|
kwargs["only"] = self.views[view]
|
|
elif isinstance(view, list):
|
|
kwargs["only"] = view
|
|
|
|
super(SubmissionSchema, self).__init__(*args, **kwargs)
|