2022-05-17 22:16:45 +02:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2022-06-06 21:30:30 +02:00
|
|
|
class StudentsPaginationSchema(ma.Schema):
|
|
|
|
students = fields.List(fields.Nested(StudentSchema))
|
|
|
|
max_pages = fields.Integer()
|
|
|
|
|
|
|
|
|
2022-05-17 22:16:45 +02:00
|
|
|
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()
|
2022-06-06 21:30:30 +02:00
|
|
|
|
|
|
|
|
|
|
|
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()
|