1
0
Fork 0
mirror of https://codeberg.org/Mo8it/AdvLabDB.git synced 2024-12-02 22:33:05 +00:00

Fix experiment mark check before adding the group experiment

This commit is contained in:
Mo 2024-03-05 17:28:44 +01:00
parent 4e0c84dee1
commit 45206e3dc4
4 changed files with 11 additions and 4 deletions

View file

@ -1075,6 +1075,9 @@ class GroupExperimentView(SecureAdminModelView):
def on_model_change(self, form, model, is_created):
if is_created:
for part_student in form.group.data.part_students:
db.session.add(ExperimentMark(part_student=part_student, group_experiment=model))
for date, special, assistant in (
(form.appointment1_date.data, form.appointment1_special.data, form.appointment1_assistant.data),
(form.appointment2_date.data, form.appointment2_special.data, form.appointment2_assistant.data),

View file

@ -10,6 +10,7 @@ from .models import (
Appointment,
Assistant,
Experiment,
ExperimentMark,
Group,
GroupExperiment,
Part,
@ -292,11 +293,14 @@ def importFromFile(filePath: Path):
dbGroupExperiments = {}
for i, id in enumerate(groupExperiments["id"]):
id = int(not_nullable(id))
group = dbGroups[int(not_nullable(groupExperiments["group_id"][i]))]
dbGroupExperiment = GroupExperiment(
semester_experiment=dbSemesterExperiments[int(not_nullable(groupExperiments["experiment_id"][i]))],
group=dbGroups[int(not_nullable(groupExperiments["group_id"][i]))],
group=group,
)
db.session.add(dbGroupExperiment)
for part_student in group.part_students:
db.session.add(ExperimentMark(part_student=part_student, group_experiment=dbGroupExperiment))
dbGroupExperiments[id] = dbGroupExperiment
# Appointment

View file

@ -281,9 +281,6 @@ class GroupExperiment(db.Model):
super().__init__(semester_experiment=semester_experiment, group=group, **kwargs)
for partStudent in group.part_students:
db.session.add(ExperimentMark(part_student=partStudent, group_experiment=self))
def update_experiment_marks_missing(self):
for experiment_mark in self.experiment_marks:
if experiment_mark.final_experiment_mark is None:

View file

@ -12,6 +12,7 @@ from advlabdb.models import (
Appointment,
Assistant,
Experiment,
ExperimentMark,
Group,
GroupExperiment,
Part,
@ -160,6 +161,8 @@ def _generate_test_db():
try:
semester_experiment = semester_experiments[ind % num_semester_experiments]
group_experiment = db_add(GroupExperiment(semester_experiment=semester_experiment, group=group))
for part_student in group.part_students:
db.session.add(ExperimentMark(part_student=part_student, group_experiment=group_experiment))
except DatabaseException as ex:
# Catch an error when a student becomes the same experiment for the second time.
# Try the next experiment!