2022-10-27 11:19:38 +02:00
|
|
|
from flask import abort
|
|
|
|
|
|
|
|
from ..dependencies import db
|
2022-11-12 16:18:07 +01:00
|
|
|
from .models import ExaminationSchedule
|
2022-10-27 11:19:38 +02:00
|
|
|
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"]}
|