mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-12-20 23:41:20 +00:00
Simplified ExperimentMarkView
This commit is contained in:
parent
05d17d151d
commit
18fac6c683
2 changed files with 16 additions and 33 deletions
|
@ -690,13 +690,10 @@ class ExperimentMarkView(SecureAdminModelView):
|
|||
blank_text="-",
|
||||
)
|
||||
|
||||
markChoices = [(-1, "-")] + list(zip(range(16)[::-1], range(16)[::-1]))
|
||||
|
||||
oral_mark = SelectField("Oral Mark", choices=markChoices, coerce=int)
|
||||
protocol_mark = SelectField("Protocol Mark", choices=markChoices, coerce=int)
|
||||
|
||||
form = CreateForm
|
||||
|
||||
can_edit = False
|
||||
|
||||
column_descriptions = {
|
||||
"oral_mark": "Between 0 and 15",
|
||||
"protocol_mark": "Between 0 and 15",
|
||||
|
@ -731,35 +728,12 @@ class ExperimentMarkView(SecureAdminModelView):
|
|||
)
|
||||
"""
|
||||
|
||||
def checkForm(form):
|
||||
if form.oral_mark and form.oral_mark.data == -1:
|
||||
form.oral_mark.data = None
|
||||
|
||||
if form.protocol_mark and form.protocol_mark.data == -1:
|
||||
form.protocol_mark.data = None
|
||||
|
||||
return form
|
||||
|
||||
def create_model(self, form):
|
||||
form = ExperimentMarkView.checkForm(form)
|
||||
|
||||
model = super().create_model(form)
|
||||
|
||||
if model and (model.oral_mark or model.protocol_mark):
|
||||
try:
|
||||
model.edited_by_admin = True
|
||||
|
||||
self.session.commit()
|
||||
except Exception as ex:
|
||||
flash(str(ex), "error")
|
||||
|
||||
self.session.rollback()
|
||||
|
||||
return model
|
||||
def customCreateModel(self, form):
|
||||
return ExperimentMark.customInit(
|
||||
part_student=form.part_student.data, group_experiment=form.group_experiment.data
|
||||
)
|
||||
|
||||
def update_model(self, form, model):
|
||||
form = ExperimentMarkView.checkForm(form)
|
||||
|
||||
if (form.oral_mark and form.oral_mark.data != model.oral_mark) or (
|
||||
form.protocol_mark and form.protocol_mark.data != model.protocol_mark
|
||||
):
|
||||
|
|
|
@ -294,7 +294,7 @@ class Appointment(db.Model):
|
|||
semesterExperimentAssistants = semesterExperiment.assistants
|
||||
|
||||
if not semesterExperimentAssistants:
|
||||
raise Exception(f"{semesterExperiment} has no assistants yet!")
|
||||
raise Exception(f"{semesterExperiment} does not have assistants yet!")
|
||||
|
||||
if assistant:
|
||||
if assistant not in semesterExperimentAssistants:
|
||||
|
@ -423,6 +423,15 @@ class ExperimentMark(db.Model):
|
|||
|
||||
__table_args__ = (db.UniqueConstraint(part_student_id, group_experiment_id),)
|
||||
|
||||
def customInit(part_student, group_experiment):
|
||||
if not part_student.group:
|
||||
raise DataBaseException("The part student does not have a group yet!")
|
||||
else:
|
||||
if group_experiment not in part_student.group.group_experiments:
|
||||
raise DataBaseException("The group of the part student does not have the given group experiment!")
|
||||
|
||||
return ExperimentMark(part_student=part_student, group_experiment=group_experiment)
|
||||
|
||||
def repr(self):
|
||||
return f"Oral {self.oral_mark}; Prot {self.protocol_mark}"
|
||||
|
||||
|
|
Loading…
Reference in a new issue