update assign_your_group_to_term_of_defence for student view - add checking open enrollments status of examination schedule before add group to term of defenece
This commit is contained in:
parent
40274dc8d7
commit
5fda4127cd
@ -1,6 +1,7 @@
|
|||||||
from apiflask import APIBlueprint
|
from apiflask import APIBlueprint
|
||||||
from flask import abort
|
from flask import abort
|
||||||
|
|
||||||
|
from ...base.mode import EnrollmentsMode
|
||||||
from ...base.schemas import MessageSchema
|
from ...base.schemas import MessageSchema
|
||||||
from ...dependencies import db
|
from ...dependencies import db
|
||||||
from ...examination_schedule.models import ExaminationSchedule
|
from ...examination_schedule.models import ExaminationSchedule
|
||||||
@ -38,14 +39,17 @@ def assign_your_group_to_term_of_defence(
|
|||||||
if term_of_defence is None or (ex := term_of_defence.examination_schedule) is None:
|
if term_of_defence is None or (ex := term_of_defence.examination_schedule) is None:
|
||||||
abort(400, "Term of defence not found!")
|
abort(400, "Term of defence not found!")
|
||||||
|
|
||||||
g = (
|
if ex.open_enrollments != EnrollmentsMode.OPEN.value:
|
||||||
|
abort(400, "Enrollments is closed! You have been delayed!")
|
||||||
|
|
||||||
|
group = (
|
||||||
Group.query.join(ProjectSupervisor)
|
Group.query.join(ProjectSupervisor)
|
||||||
.filter(Group.year_group_id == ex.year_group_id)
|
.filter(Group.year_group_id == ex.year_group_id)
|
||||||
.join(Group.students)
|
.join(Group.students)
|
||||||
.filter_by(index=student.index)
|
.filter_by(index=student.index)
|
||||||
.first()
|
.first()
|
||||||
)
|
)
|
||||||
if g is None or g.project_supervisor is None:
|
if group is None or group.project_supervisor is None:
|
||||||
abort(
|
abort(
|
||||||
400,
|
400,
|
||||||
"You don't have a group or your group doesn't"
|
"You don't have a group or your group doesn't"
|
||||||
@ -53,7 +57,7 @@ def assign_your_group_to_term_of_defence(
|
|||||||
)
|
)
|
||||||
|
|
||||||
defence = TermOfDefence.query.filter(
|
defence = TermOfDefence.query.filter(
|
||||||
TermOfDefence.group_id == g.id,
|
TermOfDefence.group_id == group.id,
|
||||||
TermOfDefence.examination_schedule_id == examination_schedule_id,
|
TermOfDefence.examination_schedule_id == examination_schedule_id,
|
||||||
).first()
|
).first()
|
||||||
if defence is not None:
|
if defence is not None:
|
||||||
@ -61,14 +65,14 @@ def assign_your_group_to_term_of_defence(
|
|||||||
|
|
||||||
td = (
|
td = (
|
||||||
TermOfDefence.query.join(TermOfDefence.members_of_committee)
|
TermOfDefence.query.join(TermOfDefence.members_of_committee)
|
||||||
.filter_by(id=g.project_supervisor_id)
|
.filter_by(id=group.project_supervisor_id)
|
||||||
.first()
|
.first()
|
||||||
)
|
)
|
||||||
|
|
||||||
if td is None:
|
if td is None:
|
||||||
abort(400, "Your project supervisor is not in committee!")
|
abort(400, "Your project supervisor is not in committee!")
|
||||||
|
|
||||||
term_of_defence.group_id = g.id
|
term_of_defence.group_id = group.id
|
||||||
db.session.add(term_of_defence)
|
db.session.add(term_of_defence)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return {"message": "You have just assigned the group for this exam date!"}
|
return {"message": "You have just assigned the group for this exam date!"}
|
||||||
|
Loading…
Reference in New Issue
Block a user