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 flask import abort
|
||||
|
||||
from ...base.mode import EnrollmentsMode
|
||||
from ...base.schemas import MessageSchema
|
||||
from ...dependencies import db
|
||||
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:
|
||||
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)
|
||||
.filter(Group.year_group_id == ex.year_group_id)
|
||||
.join(Group.students)
|
||||
.filter_by(index=student.index)
|
||||
.first()
|
||||
)
|
||||
if g is None or g.project_supervisor is None:
|
||||
if group is None or group.project_supervisor is None:
|
||||
abort(
|
||||
400,
|
||||
"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(
|
||||
TermOfDefence.group_id == g.id,
|
||||
TermOfDefence.group_id == group.id,
|
||||
TermOfDefence.examination_schedule_id == examination_schedule_id,
|
||||
).first()
|
||||
if defence is not None:
|
||||
@ -61,14 +65,14 @@ def assign_your_group_to_term_of_defence(
|
||||
|
||||
td = (
|
||||
TermOfDefence.query.join(TermOfDefence.members_of_committee)
|
||||
.filter_by(id=g.project_supervisor_id)
|
||||
.filter_by(id=group.project_supervisor_id)
|
||||
.first()
|
||||
)
|
||||
|
||||
if td is None:
|
||||
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.commit()
|
||||
return {"message": "You have just assigned the group for this exam date!"}
|
||||
|
Loading…
Reference in New Issue
Block a user