mirror of
https://github.com/aljazceru/CTFd.git
synced 2025-12-19 06:54:20 +01:00
Add initial schema changes
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
from marshmallow import fields
|
from marshmallow import fields
|
||||||
|
|
||||||
from CTFd.models import Fields, UserFieldEntries, db, ma
|
from CTFd.models import Fields, TeamFieldEntries, UserFieldEntries, db, ma
|
||||||
|
|
||||||
|
|
||||||
class FieldSchema(ma.ModelSchema):
|
class FieldSchema(ma.ModelSchema):
|
||||||
@@ -22,3 +22,17 @@ class UserFieldEntriesSchema(ma.ModelSchema):
|
|||||||
name = fields.Nested(FieldSchema, only=("name"), attribute="field")
|
name = fields.Nested(FieldSchema, only=("name"), attribute="field")
|
||||||
description = fields.Nested(FieldSchema, only=("description"), attribute="field")
|
description = fields.Nested(FieldSchema, only=("description"), attribute="field")
|
||||||
type = fields.Nested(FieldSchema, only=("field_type"), attribute="field")
|
type = fields.Nested(FieldSchema, only=("field_type"), attribute="field")
|
||||||
|
|
||||||
|
|
||||||
|
class TeamFieldEntriesSchema(ma.ModelSchema):
|
||||||
|
class Meta:
|
||||||
|
model = TeamFieldEntries
|
||||||
|
sqla_session = db.session
|
||||||
|
include_fk = True
|
||||||
|
load_only = ("id",)
|
||||||
|
exclude = ("field", "team", "team_id")
|
||||||
|
dump_only = ("team_id", "name", "description", "type")
|
||||||
|
|
||||||
|
name = fields.Nested(FieldSchema, only=("name"), attribute="field")
|
||||||
|
description = fields.Nested(FieldSchema, only=("description"), attribute="field")
|
||||||
|
type = fields.Nested(FieldSchema, only=("field_type"), attribute="field")
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
from marshmallow import ValidationError, pre_load, validate
|
from marshmallow import ValidationError, pre_load, validate
|
||||||
|
from marshmallow.fields import Nested
|
||||||
from marshmallow_sqlalchemy import field_for
|
from marshmallow_sqlalchemy import field_for
|
||||||
|
|
||||||
from CTFd.models import Teams, Users, ma
|
from CTFd.models import TeamFieldEntries, TeamFields, Teams, Users, ma
|
||||||
|
from CTFd.schemas.fields import TeamFieldEntriesSchema
|
||||||
from CTFd.utils import get_config, string_types
|
from CTFd.utils import get_config, string_types
|
||||||
from CTFd.utils.crypto import verify_password
|
from CTFd.utils.crypto import verify_password
|
||||||
from CTFd.utils.user import get_current_team, get_current_user, is_admin
|
from CTFd.utils.user import get_current_team, get_current_user, is_admin
|
||||||
@@ -44,6 +46,9 @@ class TeamSchema(ma.ModelSchema):
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
country = field_for(Teams, "country", validate=[validate_country_code])
|
country = field_for(Teams, "country", validate=[validate_country_code])
|
||||||
|
fields = Nested(
|
||||||
|
TeamFieldEntriesSchema, partial=True, many=True, attribute="field_entries"
|
||||||
|
)
|
||||||
|
|
||||||
@pre_load
|
@pre_load
|
||||||
def validate_name(self, data):
|
def validate_name(self, data):
|
||||||
@@ -197,6 +202,7 @@ class TeamSchema(ma.ModelSchema):
|
|||||||
"id",
|
"id",
|
||||||
"oauth_id",
|
"oauth_id",
|
||||||
"captain_id",
|
"captain_id",
|
||||||
|
"fields",
|
||||||
],
|
],
|
||||||
"self": [
|
"self": [
|
||||||
"website",
|
"website",
|
||||||
@@ -210,6 +216,7 @@ class TeamSchema(ma.ModelSchema):
|
|||||||
"oauth_id",
|
"oauth_id",
|
||||||
"password",
|
"password",
|
||||||
"captain_id",
|
"captain_id",
|
||||||
|
"fields",
|
||||||
],
|
],
|
||||||
"admin": [
|
"admin": [
|
||||||
"website",
|
"website",
|
||||||
@@ -227,6 +234,7 @@ class TeamSchema(ma.ModelSchema):
|
|||||||
"oauth_id",
|
"oauth_id",
|
||||||
"password",
|
"password",
|
||||||
"captain_id",
|
"captain_id",
|
||||||
|
"fields",
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -236,5 +244,6 @@ class TeamSchema(ma.ModelSchema):
|
|||||||
kwargs["only"] = self.views[view]
|
kwargs["only"] = self.views[view]
|
||||||
elif isinstance(view, list):
|
elif isinstance(view, list):
|
||||||
kwargs["only"] = view
|
kwargs["only"] = view
|
||||||
|
self.view = view
|
||||||
|
|
||||||
super(TeamSchema, self).__init__(*args, **kwargs)
|
super(TeamSchema, self).__init__(*args, **kwargs)
|
||||||
|
|||||||
Reference in New Issue
Block a user