update the list of students route for coordinator - add search by mode

This commit is contained in:
dominik24c 2022-06-10 18:18:15 +02:00
parent 2a846d4394
commit 850671e147
4 changed files with 10 additions and 7 deletions

View File

@ -25,11 +25,12 @@ def list_students(query: dict) -> dict:
fullname = query.get('fullname')
order_by_first_name = query.get('order_by_first_name')
order_by_last_name = query.get('order_by_last_name')
mode = query.get('mode')
page = query.get('page')
per_page = query.get('per_page')
student_query = Student.search_by_fullname_and_order_by_first_name_or_last_name(fullname, order_by_first_name,
order_by_last_name)
student_query = Student.search_by_fullname_and_mode_and_order_by_first_name_or_last_name(
fullname, mode, order_by_first_name, order_by_last_name)
response = paginate_models(page, student_query, per_page)
if (message := response.get('message')) is not None:

View File

@ -55,3 +55,4 @@ class StudentQuerySchema(ma.Schema):
order_by_first_name = fields.Str()
order_by_last_name = fields.Str()
page = fields.Integer()
mode = fields.Boolean()

View File

@ -1,7 +1,3 @@
from flask import Blueprint
from .groups import bp as bp_group
bp = Blueprint("project_supervisor", __name__, url_prefix="/project_supervisor")
bp.register_blueprint(bp_group)

View File

@ -25,11 +25,16 @@ class Student(Person):
mode = db.Column(db.Boolean, default=True, nullable=False) # True - stationary, False - non-stationary
@classmethod
def search_by_fullname_and_order_by_first_name_or_last_name(cls, fullname: str = None,
def search_by_fullname_and_mode_and_order_by_first_name_or_last_name(cls, fullname: str = None,
mode: bool = None,
order_by_first_name: str = None,
order_by_last_name: str = None) -> BaseQuery:
student_query = cls.query
if mode is None:
mode = True
student_query = student_query.filter_by(mode=mode)
if fullname is not None:
"""This works only for sqlite3 database - concat function doesn't exist so i used builtin concat
operator specific only for sqlite db - || """