From 43678dd18b17b6f6c552b26890921d8cd9c6d8b0 Mon Sep 17 00:00:00 2001 From: Mo8it Date: Mon, 16 Aug 2021 23:30:30 +0200 Subject: [PATCH] Added weightings default and check --- advlabdb/models.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/advlabdb/models.py b/advlabdb/models.py index 3c9086b..8cfc3b5 100644 --- a/advlabdb/models.py +++ b/advlabdb/models.py @@ -210,6 +210,21 @@ class Experiment(db.Model): __table_args__ = (db.UniqueConstraint(number, program_id),) + def checkWeightings(self, roundWeightings=False): + roundedOralWeighting = round(self.oral_weighting, 2) + roundedProtocolWeighting = round(self.protocol_weighting, 2) + + weightingSum = round(roundedOralWeighting + roundedProtocolWeighting, 2) + + if weightingSum != 1: + raise DataBaseException( + f"Oral and protocol weighting (rounded to 2 decimal digits) sum to {weightingSum} and not 1.00!" + ) + + if roundWeightings: + self.oral_weighting = roundedOralWeighting + self.protocol_weighting = roundedProtocolWeighting + def repr(self): return f"{self.number} {self.program.repr()}" @@ -381,10 +396,18 @@ class ExperimentMark(db.Model): id = db.Column(db.Integer, primary_key=True) oral_mark = db.Column( - db.Integer, db.CheckConstraint("oral_mark > -1"), db.CheckConstraint("oral_mark < 16"), nullable=True + db.Integer, + db.CheckConstraint("oral_mark > -1"), + db.CheckConstraint("oral_mark < 16"), + default=0.5, + nullable=True, ) protocol_mark = db.Column( - db.Integer, db.CheckConstraint("protocol_mark > -1"), db.CheckConstraint("protocol_mark < 16"), nullable=True + db.Integer, + db.CheckConstraint("protocol_mark > -1"), + db.CheckConstraint("protocol_mark < 16"), + default=0.5, + nullable=True, ) edited_by_admin = db.Column(db.Boolean, default=False, nullable=False)