2022-06-12 23:09:34 +02:00
|
|
|
from flask_sqlalchemy import BaseQuery
|
2022-06-10 17:53:32 +02:00
|
|
|
|
2022-10-25 20:38:47 +02:00
|
|
|
from ..dependencies import db
|
|
|
|
from ..base.models import Person, Base
|
2022-06-12 23:09:34 +02:00
|
|
|
from ..base.utils import order_by_column_name
|
2022-11-12 16:18:07 +01:00
|
|
|
from ..students.models import YearGroup
|
|
|
|
|
|
|
|
|
|
|
|
class YearGroupProjectSupervisors(Base):
|
|
|
|
__tablename__ = 'year_group_project_supervisors'
|
|
|
|
|
|
|
|
project_supervisor_id = db.Column(db.Integer, db.ForeignKey('project_supervisors.id'), nullable=False)
|
|
|
|
year_group_id = db.Column(db.Integer, db.ForeignKey('year_groups.id'), nullable=False)
|
|
|
|
limit_group = db.Column(db.Integer, default=3, nullable=False)
|
2022-06-10 17:53:32 +02:00
|
|
|
|
2022-06-13 17:52:15 +02:00
|
|
|
|
2022-06-10 17:53:32 +02:00
|
|
|
class ProjectSupervisor(Base, Person):
|
|
|
|
__tablename__ = "project_supervisors"
|
|
|
|
|
2022-11-12 16:18:07 +01:00
|
|
|
year_groups = db.relationship('YearGroupProjectSupervisors', lazy=True)
|
2022-06-12 23:09:34 +02:00
|
|
|
|
|
|
|
@classmethod
|
2022-11-12 16:18:07 +01:00
|
|
|
def search_by_fullname_and_mode_and_order_by_first_name_or_last_name(cls, year_group_id: int = None,
|
|
|
|
fullname: str = None,
|
2022-06-12 23:09:34 +02:00
|
|
|
order_by_first_name: str = None,
|
|
|
|
order_by_last_name: str = None) -> BaseQuery:
|
|
|
|
project_supervisors_query = cls.query
|
|
|
|
|
2022-11-12 16:18:07 +01:00
|
|
|
if year_group_id is not None:
|
2023-01-03 21:12:29 +01:00
|
|
|
project_supervisors_query = project_supervisors_query.join(YearGroupProjectSupervisors). \
|
|
|
|
filter(YearGroupProjectSupervisors.year_group_id == year_group_id)
|
2022-06-12 23:09:34 +02:00
|
|
|
|
|
|
|
if fullname is not None:
|
|
|
|
project_supervisors_query = project_supervisors_query.filter(
|
2022-06-13 17:52:15 +02:00
|
|
|
(ProjectSupervisor.first_name + ' ' + ProjectSupervisor.last_name).like(f'{fullname}%'))
|
2022-06-12 23:09:34 +02:00
|
|
|
|
2022-06-13 17:52:15 +02:00
|
|
|
project_supervisors_query = order_by_column_name(project_supervisors_query, ProjectSupervisor.first_name,
|
|
|
|
order_by_first_name)
|
|
|
|
project_supervisors_query = order_by_column_name(project_supervisors_query, ProjectSupervisor.last_name,
|
|
|
|
order_by_last_name)
|
2022-06-12 23:09:34 +02:00
|
|
|
|
|
|
|
return project_supervisors_query
|