mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-12-20 23:41:20 +00:00
Fix checkThenSetFinalPartMark
This commit is contained in:
parent
a8eee63b9e
commit
7b9761d37b
1 changed files with 28 additions and 12 deletions
|
@ -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,7 +140,9 @@ class PartStudent(db.Model):
|
||||||
flash(str(ex), "error")
|
flash(str(ex), "error")
|
||||||
|
|
||||||
db.session.rollback()
|
db.session.rollback()
|
||||||
else:
|
return False
|
||||||
|
|
||||||
|
# Inform admin about what changed
|
||||||
if current_user.has_role("admin"):
|
if current_user.has_role("admin"):
|
||||||
if oldFinalPartMark != self.final_part_mark:
|
if oldFinalPartMark != self.final_part_mark:
|
||||||
category = "danger" if oldFinalPartMark and oldFinalPartMark > self.final_part_mark else "info"
|
category = "danger" if oldFinalPartMark and oldFinalPartMark > self.final_part_mark else "info"
|
||||||
|
@ -140,6 +154,8 @@ class PartStudent(db.Model):
|
||||||
else:
|
else:
|
||||||
flash(f"Final part mark did not change for {self} from {oldFinalPartMark}.", "warning")
|
flash(f"Final part mark did not change for {self} from {oldFinalPartMark}.", "warning")
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
class Group(db.Model):
|
class Group(db.Model):
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
|
Loading…
Reference in a new issue