from marshmallow import Schema, fields, validate from ...dependencies import ma from ...students.models import Group, Student from ..validators import validate_index from .project_supervisor import ProjectSupervisorSchema class GroupSchema(ma.SQLAlchemyAutoSchema): project_supervisor = fields.Nested(ProjectSupervisorSchema) class Meta: model = Group class StudentSchema(ma.SQLAlchemyAutoSchema): groups = fields.List(fields.Nested(GroupSchema)) class Meta: model = Student class StudentsPaginationSchema(ma.Schema): students = fields.List(fields.Nested(StudentSchema)) max_pages = fields.Integer() class StudentListFileDownloaderSchema(ma.Schema): year_group_id = fields.Integer(required=True) 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) year_group_id = fields.Integer() 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) class MessageWithIdSchema(ma.Schema): message = fields.Str(required=True) id = fields.Str(required=False) class FileSchema(ma.Schema): file = fields.Raw(metadata={"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() per_page = fields.Integer() class YearGroupInfoQuery(Schema): year_group_id = fields.Integer(required=True) class DetailGroupSchema(ma.SQLAlchemyAutoSchema): project_supervisor = fields.Nested(ProjectSupervisorSchema) students = fields.List( fields.Nested(StudentSchema), validate=validate.Length(min=1, max=255) ) class Meta: model = Group