This repository has been archived by the owner on Apr 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschemas.py
65 lines (55 loc) · 1.84 KB
/
schemas.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from marshmallow import validate, ValidationError, pre_load
from marshmallow_sqlalchemy import field_for
from CTFd.utils import get_config
from CTFd.utils.user import is_admin, get_current_user
from CTFd.utils import string_types
from CTFd.models import ma
from .db_tables import Attributes, AttributesSelectOptions, IntersectionTeamAttr
class AttributesSelectOptionsSchema(ma.ModelSchema):
class Meta:
model = AttributesSelectOptions
include_fk = True
dump_only = ("id")
views = {
"admin": ["id", "name", "value", "attr_id"],
"user": ["id", "name", "value", "attr_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(AttributesSelectOptionsSchema, self).__init__(*args, **kwargs)
class AttributesSchema(ma.ModelSchema):
class Meta:
model = Attributes
include_fk = True
dump_only = ("id")
views = {
"admin": ["id", "name", "type", "default", "hidden", "private", "frozen"],
"user": ["id", "name", "type", "default", "frozen"]
}
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(AttributesSchema, self).__init__(*args, **kwargs)
class IntersectionTeamAttrSchema(ma.ModelSchema):
class Meta:
model = IntersectionTeamAttr
include_fk = True
dump_only = ("id")
views = {
"admin": ["id", "team_id", "attr_id", "value"],
"user": ["id", "team_id", "attr_id", "value"]
}
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(IntersectionTeamAttrSchema, self).__init__(*args, **kwargs)