2022-10-27 11:19:38 +02:00
|
|
|
import datetime
|
|
|
|
|
2022-10-26 15:11:50 +02:00
|
|
|
from apiflask import APIBlueprint
|
2022-10-27 11:19:38 +02:00
|
|
|
from flask import abort
|
|
|
|
|
|
|
|
from ..schemas import EnrollmentPaginationSchema, EnrollmentQuerySchema
|
|
|
|
from ..utils import check_examination_schedule_is_exist, get_list_of_enrollments_response
|
2022-10-26 15:11:50 +02:00
|
|
|
|
|
|
|
bp = APIBlueprint("enrollments", __name__, url_prefix="/enrollments")
|
|
|
|
|
|
|
|
|
2022-10-27 11:19:38 +02:00
|
|
|
# list of the exam registration for students
|
|
|
|
@bp.get('/<int:examination_schedule_id>/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('/<int:examination_schedule_id>/coordinator-view/')
|
|
|
|
@bp.input(EnrollmentQuerySchema, location='query')
|
|
|
|
@bp.output(EnrollmentPaginationSchema)
|
|
|
|
def list_enrollments_for_coordinator(examination_schedule_id: int, query: dict) -> dict:
|
|
|
|
page = query.get('page')
|
|
|
|
per_page = query.get('per_page')
|
|
|
|
|
|
|
|
check_examination_schedule_is_exist(examination_schedule_id)
|
|
|
|
|
|
|
|
return get_list_of_enrollments_response(examination_schedule_id, page, per_page)
|
|
|
|
|
|
|
|
|
|
|
|
@bp.get('/<int:examination_schedule_id>/project-supervisor-view/')
|
|
|
|
@bp.input(EnrollmentQuerySchema, location='query')
|
|
|
|
@bp.output(EnrollmentPaginationSchema)
|
|
|
|
def list_enrollments_for_project_supervisor(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.timestamp() < now.timestamp():
|
|
|
|
abort(403, "Forbidden! Enrollment has just started! You cannot assign to the exam committees!")
|
|
|
|
|
|
|
|
return get_list_of_enrollments_response(examination_schedule_id, page, per_page)
|