system-pri/backend/app/project_supervisor/query.py

34 lines
1.3 KiB
Python

import datetime
from flask import abort
from ..dependencies import db
from ..examination_schedule.models import Enrollment, ExaminationSchedule, Committee
def get_enrollment_by_enrollment_and_examination_schedule_ids(examination_schedule_id: int,
enrollment_id: int) -> Enrollment:
enrollment = db.session.query(Enrollment). \
join(ExaminationSchedule, isouter=True).join(Committee, isouter=True). \
filter(ExaminationSchedule.id == examination_schedule_id). \
filter(Enrollment.id == enrollment_id). \
first()
if enrollment is None:
abort(404, "Examination schedule doesn't exist!")
return enrollment
def check_the_project_supervisor_is_in_committee(enrollment_id: int, project_supervisor_id) -> bool:
return db.session.query(
Committee.query.join(Committee.members).filter(Committee.enrollment_id == enrollment_id).filter(
Committee.members.any(id=project_supervisor_id)).exists()).scalar()
def check_the_enrollments_has_just_started(start_date: datetime.datetime, action: str) -> None:
now = datetime.datetime.utcnow()
if start_date is not None and start_date.timestamp() < now.timestamp():
abort(403, f"Forbidden! Enrollment has just started! You cannot {action} from the exam committees!")