2023-01-14 17:38:03 +01:00
|
|
|
from marshmallow import Schema, fields, validate
|
2022-10-26 12:41:22 +02:00
|
|
|
|
|
|
|
from ...dependencies import ma
|
2023-01-14 17:38:03 +01:00
|
|
|
from ...students.models import Group, Student
|
2022-10-26 12:41:22 +02:00
|
|
|
from ..validators import validate_index
|
2023-01-14 17:38:03 +01:00
|
|
|
from .project_supervisor import ProjectSupervisorSchema
|
2022-10-26 12:41:22 +02:00
|
|
|
|
|
|
|
|
|
|
|
class GroupSchema(ma.SQLAlchemyAutoSchema):
|
|
|
|
project_supervisor = fields.Nested(ProjectSupervisorSchema)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Group
|
|
|
|
|
|
|
|
|
|
|
|
class StudentSchema(ma.SQLAlchemyAutoSchema):
|
2023-01-16 17:23:45 +01:00
|
|
|
groups = fields.List(fields.Nested(GroupSchema))
|
2022-10-26 12:41:22 +02:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Student
|
|
|
|
|
|
|
|
|
|
|
|
class StudentsPaginationSchema(ma.Schema):
|
|
|
|
students = fields.List(fields.Nested(StudentSchema))
|
|
|
|
max_pages = fields.Integer()
|
|
|
|
|
|
|
|
|
|
|
|
class StudentListFileDownloaderSchema(ma.Schema):
|
2022-11-17 14:56:19 +01:00
|
|
|
year_group_id = fields.Integer(required=True)
|
2022-10-26 12:41:22 +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)
|
2022-11-12 16:18:07 +01:00
|
|
|
year_group_id = fields.Integer()
|
2022-10-26 12:41:22 +02:00
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
2023-01-14 01:37:31 +01:00
|
|
|
class MessageWithIdSchema(ma.Schema):
|
2022-10-26 12:41:22 +02:00
|
|
|
message = fields.Str(required=True)
|
2022-12-16 03:28:27 +01:00
|
|
|
id = fields.Str(required=False)
|
2022-10-26 12:41:22 +02:00
|
|
|
|
2023-01-04 22:51:58 +01:00
|
|
|
|
2022-10-26 12:41:22 +02:00
|
|
|
class FileSchema(ma.Schema):
|
2023-01-14 17:38:03 +01:00
|
|
|
file = fields.Raw(metadata={"type": "file"}, required=True)
|
2022-10-26 12:41:22 +02:00
|
|
|
|
|
|
|
|
|
|
|
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()
|
2022-11-17 14:56:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
class YearGroupInfoQuery(Schema):
|
2023-01-14 01:37:31 +01:00
|
|
|
year_group_id = fields.Integer(required=True)
|
2023-01-06 19:24:02 +01:00
|
|
|
|
2023-01-14 17:38:03 +01:00
|
|
|
|
2023-01-06 19:24:02 +01:00
|
|
|
class DetailGroupSchema(ma.SQLAlchemyAutoSchema):
|
|
|
|
project_supervisor = fields.Nested(ProjectSupervisorSchema)
|
2023-01-14 17:38:03 +01:00
|
|
|
students = fields.List(
|
|
|
|
fields.Nested(StudentSchema), validate=validate.Length(min=1, max=255)
|
|
|
|
)
|
|
|
|
|
2023-01-06 19:24:02 +01:00
|
|
|
class Meta:
|
2023-01-14 17:38:03 +01:00
|
|
|
model = Group
|