1
0
Fork 0
mirror of https://codeberg.org/Mo8it/AdvLabDB.git synced 2024-12-20 23:41:20 +00:00

Fix checkThenSetFinalPartMark

This commit is contained in:
Mo 2022-06-30 17:29:52 +02:00
parent a8eee63b9e
commit 7b9761d37b

View file

@ -95,6 +95,9 @@ class PartStudent(db.Model):
super().__init__(student=student, part=part, group=group) super().__init__(student=student, part=part, group=group)
def checkThenSetFinalPartMark(self): def checkThenSetFinalPartMark(self):
"""
Return True if final_part_mark changed, False otherwise.
"""
finalWeightingSum = 0 finalWeightingSum = 0
finalMark = 0 finalMark = 0
groupExperiments = [] groupExperiments = []
@ -102,7 +105,16 @@ class PartStudent(db.Model):
for experimentMark in self.experiment_marks: for experimentMark in self.experiment_marks:
if None in (experimentMark.oral_mark, experimentMark.protocol_mark): if None in (experimentMark.oral_mark, experimentMark.protocol_mark):
# Not all marks are set! # Not all marks are set!
return try:
self.final_part_mark = None
db.session.commit()
return True
except Exception as ex:
flash(str(ex), "error")
db.session.rollback()
return False
groupExperiment = experimentMark.group_experiment groupExperiment = experimentMark.group_experiment
groupExperiments.append(groupExperiment) groupExperiments.append(groupExperiment)
@ -116,7 +128,7 @@ class PartStudent(db.Model):
if set(groupExperiments) != set(self.group.group_experiments): if set(groupExperiments) != set(self.group.group_experiments):
flash(f"{self} does not have an experiment mark for every group experiment in his group!", "warning") flash(f"{self} does not have an experiment mark for every group experiment in his group!", "warning")
return return False
oldFinalPartMark = self.final_part_mark oldFinalPartMark = self.final_part_mark
@ -128,17 +140,21 @@ class PartStudent(db.Model):
flash(str(ex), "error") flash(str(ex), "error")
db.session.rollback() db.session.rollback()
else: return False
if current_user.has_role("admin"):
if oldFinalPartMark != self.final_part_mark:
category = "danger" if oldFinalPartMark and oldFinalPartMark > self.final_part_mark else "info"
flash( # Inform admin about what changed
f"Final part mark changed for {self} from {oldFinalPartMark} to {self.final_part_mark}.", if current_user.has_role("admin"):
category, if oldFinalPartMark != self.final_part_mark:
) category = "danger" if oldFinalPartMark and oldFinalPartMark > self.final_part_mark else "info"
else:
flash(f"Final part mark did not change for {self} from {oldFinalPartMark}.", "warning") flash(
f"Final part mark changed for {self} from {oldFinalPartMark} to {self.final_part_mark}.",
category,
)
else:
flash(f"Final part mark did not change for {self} from {oldFinalPartMark}.", "warning")
return True
class Group(db.Model): class Group(db.Model):