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)
def checkThenSetFinalPartMark(self):
"""
Return True if final_part_mark changed, False otherwise.
"""
finalWeightingSum = 0
finalMark = 0
groupExperiments = []
@ -102,7 +105,16 @@ class PartStudent(db.Model):
for experimentMark in self.experiment_marks:
if None in (experimentMark.oral_mark, experimentMark.protocol_mark):
# 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
groupExperiments.append(groupExperiment)
@ -116,7 +128,7 @@ class PartStudent(db.Model):
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")
return
return False
oldFinalPartMark = self.final_part_mark
@ -128,17 +140,21 @@ class PartStudent(db.Model):
flash(str(ex), "error")
db.session.rollback()
else:
if current_user.has_role("admin"):
if oldFinalPartMark != self.final_part_mark:
category = "danger" if oldFinalPartMark and oldFinalPartMark > self.final_part_mark else "info"
return False
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")
# Inform admin about what changed
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(
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):