2022-06-10 17:53:32 +02:00
|
|
|
from ..dependencies import db
|
|
|
|
from ..base.models import Person, Base
|
2022-06-12 23:09:34 +02:00
|
|
|
from flask_sqlalchemy import BaseQuery
|
2022-06-10 17:53:32 +02:00
|
|
|
|
2022-06-12 23:09:34 +02:00
|
|
|
from sqlalchemy import or_
|
|
|
|
from sqlalchemy.sql import text
|
|
|
|
from ..base.utils import order_by_column_name
|
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-06-12 23:09:34 +02:00
|
|
|
limit_group = db.Column(db.Integer, default=3, nullable=False)
|
|
|
|
count_groups = db.Column(db.Integer, default=0, nullable=False)
|
2022-06-12 15:38:44 +02:00
|
|
|
mode = db.Column(db.Integer, default=0, nullable=False) # 0 - stationary, 1 - non-stationary, 2 - both
|
2022-06-12 23:09:34 +02:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def search_by_fullname_and_mode_and_order_by_first_name_or_last_name(cls, fullname: str = None,
|
|
|
|
mode: int = None,
|
|
|
|
order_by_first_name: str = None,
|
|
|
|
order_by_last_name: str = None) -> BaseQuery:
|
|
|
|
project_supervisors_query = cls.query
|
|
|
|
|
|
|
|
if mode is not None:
|
2022-06-13 17:52:15 +02:00
|
|
|
project_supervisors_query = project_supervisors_query.filter(mode != 1 - mode)
|
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
|