28 lines
1.0 KiB
Python
28 lines
1.0 KiB
Python
from flask import abort
|
|
|
|
from ..dependencies import db
|
|
from .models import ExaminationSchedule
|
|
from ..students.models import Group
|
|
from ..base.utils import paginate_models
|
|
|
|
|
|
def check_examination_schedule_is_exist(examination_schedule_id: int) -> ExaminationSchedule:
|
|
examination_schedule = db.session.query(ExaminationSchedule).filter(
|
|
ExaminationSchedule.id == examination_schedule_id).first()
|
|
|
|
if examination_schedule is None:
|
|
abort(404, "Examination Schedule doesn't exist!")
|
|
|
|
return examination_schedule
|
|
|
|
|
|
def get_list_of_enrollments_response(examination_schedule_id: int, page: int = None, per_page: int = None) -> dict:
|
|
enrollments_query = db.session.query(Enrollment). \
|
|
join(Group, isouter=True).join(Committee, isouter=True). \
|
|
join(ExaminationSchedule, isouter=True). \
|
|
filter(ExaminationSchedule.id == examination_schedule_id)
|
|
|
|
data = paginate_models(page, enrollments_query, per_page)
|
|
|
|
return {"enrollments": data["items"], "max_pages": data["max_pages"]}
|