2022-05-17 22:16:45 +02:00
|
|
|
from ..dependencies import ma
|
|
|
|
from ..students.models import Student, Group
|
2022-06-12 23:09:34 +02:00
|
|
|
from ..project_supervisor.models import ProjectSupervisor
|
2022-05-17 22:16:45 +02:00
|
|
|
from marshmallow import fields, validate, ValidationError
|
|
|
|
|
2022-06-13 17:52:15 +02:00
|
|
|
|
2022-05-17 22:16:45 +02:00
|
|
|
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!")
|
|
|
|
|
2022-06-12 23:09:34 +02:00
|
|
|
|
|
|
|
class ProjectSupervisorSchema(ma.SQLAlchemyAutoSchema):
|
|
|
|
class Meta:
|
|
|
|
model = ProjectSupervisor
|
|
|
|
include_relationships = False
|
|
|
|
|
|
|
|
|
2022-05-17 22:16:45 +02:00
|
|
|
class GroupSchema(ma.SQLAlchemyAutoSchema):
|
2022-06-12 17:45:45 +02:00
|
|
|
project_supervisor = fields.Nested(ProjectSupervisorSchema)
|
2022-06-13 17:52:15 +02:00
|
|
|
|
2022-05-17 22:16:45 +02:00
|
|
|
class Meta:
|
|
|
|
model = Group
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
2022-06-12 17:45:45 +02:00
|
|
|
pesel = fields.Str(validate=validate.Length(min=0, max=11), required=True)
|
2022-05-17 22:16:45 +02:00
|
|
|
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))
|
2022-06-12 17:45:45 +02:00
|
|
|
pesel = fields.Str(validate=validate.Length(min=0, max=11))
|
2022-05-17 22:16:45 +02:00
|
|
|
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()
|
2022-06-12 17:45:45 +02:00
|
|
|
per_page = fields.Integer()
|
2022-06-10 18:18:15 +02:00
|
|
|
mode = fields.Boolean()
|
2022-06-12 17:45:45 +02:00
|
|
|
|
|
|
|
|
|
|
|
class GroupQuerySchema(ma.Schema):
|
|
|
|
name = fields.Str()
|
|
|
|
page = fields.Integer()
|
|
|
|
per_page = fields.Integer()
|
|
|
|
|
|
|
|
|
|
|
|
class GroupsPaginationSchema(ma.Schema):
|
|
|
|
groups = fields.List(fields.Nested(GroupSchema))
|
|
|
|
max_pages = fields.Integer()
|
|
|
|
|
|
|
|
|
|
|
|
class GroupCreateSchema(ma.Schema):
|
|
|
|
name = fields.Str(validate=validate.Length(min=1, max=255), required=True)
|
2022-06-13 17:52:15 +02:00
|
|
|
project_supervisor_id = fields.Integer(required=True)
|
|
|
|
students = fields.List(fields.Integer(validate=validate_index, required=True))
|
2022-06-12 17:45:45 +02:00
|
|
|
|
|
|
|
|
|
|
|
class GroupEditSchema(ma.Schema):
|
|
|
|
name = fields.Str(validate=validate.Length(min=1, max=255))
|
|
|
|
project_supervisor_id = fields.Integer(validate=validate_index)
|
2022-06-12 23:09:34 +02:00
|
|
|
students = fields.List(fields.Nested(StudentSchema), validate=validate.Length(min=1, max=255))
|
|
|
|
|
|
|
|
|
|
|
|
class ProjectSupervisorQuerySchema(ma.Schema):
|
|
|
|
fullname = fields.Str()
|
|
|
|
order_by_first_name = fields.Str()
|
|
|
|
order_by_last_name = fields.Str()
|
|
|
|
page = fields.Integer()
|
|
|
|
per_page = fields.Integer()
|
|
|
|
mode = fields.Integer()
|
|
|
|
|
|
|
|
|
|
|
|
class ProjectSupervisorsPaginationSchema(ma.Schema):
|
|
|
|
project_supervisors = fields.List(fields.Nested(ProjectSupervisorSchema))
|
|
|
|
max_pages = fields.Integer()
|
|
|
|
|
|
|
|
|
|
|
|
class ProjectSupervisorCreateSchema(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)
|
2022-06-13 18:41:28 +02:00
|
|
|
email = fields.Str(validate=validate.Length(min=1, max=255), required=True)
|
|
|
|
limit_group = fields.Integer()
|
2022-06-12 23:09:34 +02:00
|
|
|
mode = fields.Integer(required=True)
|
|
|
|
|
|
|
|
|
|
|
|
class ProjectSupervisorEditSchema(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)
|
|
|
|
email = fields.Str(validate=validate.Length(min=0, max=11), required=True)
|
|
|
|
limit_group = fields.Integer(validate=validate_index)
|
|
|
|
count_groups = fields.Integer(validate=validate_index)
|
|
|
|
mode = fields.Integer(required=True)
|