import datetime from apiflask import APIBlueprint from flask import abort from ..schemas import EnrollmentPaginationSchema, EnrollmentQuerySchema, ExaminationScheduleProjectSupervisorViewSchema from ..utils import check_examination_schedule_is_exist, get_list_of_enrollments_response bp = APIBlueprint("enrollments", __name__, url_prefix="/enrollments") # list of the exam registration for students @bp.get('//student-view') @bp.input(EnrollmentQuerySchema, location='query') @bp.output(EnrollmentPaginationSchema) def list_enrollments_for_students(examination_schedule_id: int, query: dict) -> dict: page = query.get('page') per_page = query.get('per_page') examination_schedule = check_examination_schedule_is_exist(examination_schedule_id) now = datetime.datetime.utcnow() if examination_schedule.start_date is None or examination_schedule.end_date is None: abort(403, "Forbidden! The examination schedule is not available yet") if examination_schedule.start_date.timestamp() > now.timestamp(): abort(403, "Forbidden! Enrollments haven't just started!") if examination_schedule.end_date.timestamp() < now.timestamp(): abort(400, "The exam registration has just finished!") return get_list_of_enrollments_response(examination_schedule_id, page, per_page) @bp.get('//coordinator-view/') @bp.output(ExaminationScheduleProjectSupervisorViewSchema) def list_enrollments_for_coordinator(examination_schedule_id: int) -> dict: return check_examination_schedule_is_exist(examination_schedule_id)