44 lines
1.7 KiB
Python
44 lines
1.7 KiB
Python
from flask import abort
|
|
|
|
from ...examination_schedule.models import ExaminationSchedule, TermOfDefence
|
|
from ...students.models import Group
|
|
|
|
|
|
def get_term_of_defence_by_id_and_examination_schedule_id(examination_schedule_id: int,
|
|
term_of_defence_id: int) -> ExaminationSchedule:
|
|
td = TermOfDefence.query.filter(TermOfDefence.id == term_of_defence_id,
|
|
TermOfDefence.examination_schedule_id == examination_schedule_id).first()
|
|
if td is None:
|
|
abort(404, "Not found examination schedule or term of defence!")
|
|
return td
|
|
|
|
|
|
def get_group_by_id(group_id: int) -> Group:
|
|
group = Group.query.filter(Group.id == group_id).first()
|
|
if group is None:
|
|
abort(404, "Not found group!")
|
|
return group
|
|
|
|
|
|
def check_the_group_has_assigned_to_term_of_defence(group_id: int) -> TermOfDefence:
|
|
td = TermOfDefence.query.filter(TermOfDefence.group_id == group_id).first()
|
|
if td is not None:
|
|
abort(400, "Group has already assigned to term of defence!")
|
|
return td
|
|
|
|
|
|
def set_new_group_to_term_of_defence(examination_schedule_id: int, term_of_defence_id: int,
|
|
group_id: int) -> TermOfDefence:
|
|
td = get_term_of_defence_by_id_and_examination_schedule_id(examination_schedule_id, term_of_defence_id)
|
|
get_group_by_id(group_id)
|
|
check_the_group_has_assigned_to_term_of_defence(group_id)
|
|
td.group_id = group_id
|
|
return td
|
|
|
|
|
|
def get_examination_schedule_by_id(examination_schedule_id: int) -> ExaminationSchedule:
|
|
ex = ExaminationSchedule.query.filter(ExaminationSchedule.id == examination_schedule_id).first()
|
|
if ex is None:
|
|
abort(404, "Not found examination schedule!")
|
|
return ex
|