system-pri/backend/app/coordinator/schemas/year_group.py
2023-01-04 22:51:58 +01:00

31 lines
784 B
Python

from marshmallow import Schema, fields, validate, ValidationError
from ...base.mode import ModeGroups
def validate_mode(value: str) -> str:
if value not in [m.value for m in ModeGroups]:
raise ValidationError("Invalid mode!")
return value
class YearGroupSchema(Schema):
name = fields.Str(validate=validate.Regexp(r'^\d{4}/\d{4}$'), required=True)
mode = fields.Str(validate=validate_mode, required=True)
class YearGroupItemSchema(Schema):
id = fields.Integer()
name = fields.Str()
mode = fields.Str()
class YearGroupPaginationSchema(Schema):
year_groups = fields.List(fields.Nested(YearGroupItemSchema))
max_pages = fields.Integer()
class YearGroupQuerySchema(Schema):
page = fields.Integer()
per_page = fields.Integer()