system-pri/backend/app/coordinator/schemas.py
2022-06-06 21:30:30 +02:00

58 lines
1.6 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 StudentsPaginationSchema(ma.Schema):
students = fields.List(fields.Nested(StudentSchema))
max_pages = fields.Integer()
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()
class MessageSchema(ma.Schema):
message = fields.Str(required=True)
class FileSchema(ma.Schema):
file = fields.Raw(type='file', required=True)
class StudentQuerySchema(ma.Schema):
fullname = fields.Str()
order_by_first_name = fields.Str()
order_by_last_name = fields.Str()
page = fields.Integer()