from marshmallow import Schema, ValidationError, fields, validate 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()