2022-05-18 17:36:16 +02:00
|
|
|
from sqlalchemy.sql import text
|
|
|
|
from flask_sqlalchemy import BaseQuery
|
|
|
|
|
2022-05-17 22:16:45 +02:00
|
|
|
from ..dependencies import db
|
|
|
|
from ..base.models import Person, Base
|
2022-05-18 17:36:16 +02:00
|
|
|
from ..base.utils import order_by_column_name
|
2022-05-17 22:16:45 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Group(Base):
|
|
|
|
__tablename__ = "groups"
|
|
|
|
|
|
|
|
name = db.Column(db.String(60), nullable=False)
|
2022-06-12 17:45:45 +02:00
|
|
|
cdyd_kod = db.Column(db.String(60), default='2022/SZ')
|
|
|
|
prz_kod = db.Column(db.String(60), default='06-DPRILI0')
|
|
|
|
tzaj_kod = db.Column(db.String(60), default='LAB')
|
2022-05-17 22:16:45 +02:00
|
|
|
project_supervisor_id = db.Column(db.Integer, db.ForeignKey('project_supervisors.id'))
|
|
|
|
project_supervisor = db.relationship('ProjectSupervisor', backref='groups', lazy=True)
|
2022-06-11 12:53:55 +02:00
|
|
|
points_for_first_term = db.Column(db.Integer, default=0, nullable=False)
|
|
|
|
points_for_second_term = db.Column(db.Integer, default=0, nullable=False)
|
2022-05-17 22:16:45 +02:00
|
|
|
|
2022-06-12 17:45:45 +02:00
|
|
|
@classmethod
|
|
|
|
def search_by_name(cls, search_name: str = None) -> BaseQuery:
|
|
|
|
group_query = cls.query
|
|
|
|
|
|
|
|
if search_name is not None:
|
2022-06-13 17:52:15 +02:00
|
|
|
group_query = group_query.filter(Group.name.like(f'{search_name}%'))
|
2022-06-12 17:45:45 +02:00
|
|
|
|
2022-06-13 17:52:15 +02:00
|
|
|
return group_query
|
2022-06-12 17:45:45 +02:00
|
|
|
|
2022-05-17 22:16:45 +02:00
|
|
|
|
|
|
|
class Student(Person):
|
|
|
|
__tablename__ = "students"
|
|
|
|
|
2022-06-12 17:45:45 +02:00
|
|
|
pesel = db.Column(db.String(11), default='')
|
2022-05-17 22:16:45 +02:00
|
|
|
index = db.Column(db.Integer, primary_key=True)
|
|
|
|
group_id = db.Column(db.Integer, db.ForeignKey('groups.id'))
|
|
|
|
group = db.relationship('Group', backref='students', lazy=True)
|
|
|
|
mode = db.Column(db.Boolean, default=True, nullable=False) # True - stationary, False - non-stationary
|
2022-05-18 17:36:16 +02:00
|
|
|
|
|
|
|
@classmethod
|
2022-06-10 18:18:15 +02:00
|
|
|
def search_by_fullname_and_mode_and_order_by_first_name_or_last_name(cls, fullname: str = None,
|
2022-06-11 12:53:55 +02:00
|
|
|
mode: bool = None,
|
|
|
|
order_by_first_name: str = None,
|
|
|
|
order_by_last_name: str = None) -> BaseQuery:
|
2022-05-18 17:36:16 +02:00
|
|
|
student_query = cls.query
|
|
|
|
|
2022-06-11 19:41:28 +02:00
|
|
|
if mode is not None:
|
|
|
|
student_query = student_query.filter_by(mode=mode)
|
2022-06-10 18:18:15 +02:00
|
|
|
|
2022-05-18 17:36:16 +02:00
|
|
|
if fullname is not None:
|
2022-06-13 17:52:15 +02:00
|
|
|
student_query = student_query.filter((Student.first_name + ' ' + Student.last_name).like(f'{fullname}%'))
|
2022-05-18 17:36:16 +02:00
|
|
|
|
|
|
|
student_query = order_by_column_name(student_query, Student.first_name, order_by_first_name)
|
|
|
|
student_query = order_by_column_name(student_query, Student.last_name, order_by_last_name)
|
|
|
|
|
|
|
|
return student_query
|