system-pri/backend/app/coordinator/schemas.py

38 lines
1.1 KiB
Python

from ..dependencies import ma
from ..students.models import Student, Group
from marshmallow import fields, validate, ValidationError
def validate_index(index):
if len(str(index)) > 6:
raise ValidationError("Length of index is too long!")
elif len(str(index)) < 6:
raise ValidationError("Length of index is too short!")
class GroupSchema(ma.SQLAlchemyAutoSchema):
class Meta:
model = Group
include_relationships = False
class StudentSchema(ma.SQLAlchemyAutoSchema):
group = fields.Nested(GroupSchema)
class Meta:
model = Student
class StudentCreateSchema(ma.Schema):
first_name = fields.Str(validate=validate.Length(min=1, max=255), required=True)
last_name = fields.Str(validate=validate.Length(min=1, max=255), required=True)
index = fields.Integer(validate=validate_index, required=True)
mode = fields.Boolean(required=True)
class StudentEditSchema(ma.Schema):
first_name = fields.Str(validate=validate.Length(min=1, max=255))
last_name = fields.Str(validate=validate.Length(min=1, max=255))
index = fields.Integer(validate=validate_index)
mode = fields.Boolean()