From 0ee5fcd52baf8b6e17ec4c1370e61e4af31f6966 Mon Sep 17 00:00:00 2001 From: Mo8it Date: Tue, 12 Apr 2022 01:44:53 +0200 Subject: [PATCH] Add min and max mark as constants --- advlabdb/assistantModelViews.py | 10 ++++++---- advlabdb/models.py | 19 +++++++++++-------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/advlabdb/assistantModelViews.py b/advlabdb/assistantModelViews.py index fe1bbe5..e49a0f2 100644 --- a/advlabdb/assistantModelViews.py +++ b/advlabdb/assistantModelViews.py @@ -11,6 +11,8 @@ from advlabdb import assistantSpace, db from advlabdb.customClasses import SecureAssistantBaseView, SecureAssistantModelView from advlabdb.exceptions import DataBaseException, ModelViewException from advlabdb.models import ( + MAX_MARK, + MIN_MARK, Appointment, Assistant, Experiment, @@ -91,8 +93,8 @@ class AssistantExperimentMarkView(SecureAssistantModelView): "part_student.part": "Part", } column_descriptions = { - "oral_mark": "Between 0 and 15", - "protocol_mark": "Between 0 and 15", + "oral_mark": f"Between {MIN_MARK} and {MAX_MARK}", + "protocol_mark": f"Between {MIN_MARK} and {MAX_MARK}", "final_experiment_mark": "Calculated automatically with oral and protocol marks and weightings", "part_student.student.contact_email": "The preferred contact email address if entered by the student", "assistant": "The last assistant who edited the mark", @@ -106,8 +108,8 @@ class AssistantExperimentMarkView(SecureAssistantModelView): form_columns = column_editable_list form_args = { - "oral_mark": {"validators": [NumberRange(0, 15)]}, - "protocol_mark": {"validators": [NumberRange(0, 15)]}, + "oral_mark": {"validators": [NumberRange(MIN_MARK, MAX_MARK)]}, + "protocol_mark": {"validators": [NumberRange(MIN_MARK, MAX_MARK)]}, } column_default_sort = [("oral_mark", False), ("protocol_mark", False)] diff --git a/advlabdb/models.py b/advlabdb/models.py index 1697f9a..fb332e7 100644 --- a/advlabdb/models.py +++ b/advlabdb/models.py @@ -16,6 +16,9 @@ from advlabdb import db from advlabdb.configUtils import getConfig from advlabdb.exceptions import DataBaseException +MIN_MARK = 0 +MAX_MARK = 15 + def roundHalfUpToInt(number): return int(Decimal(number).quantize(Decimal(0), rounding=ROUND_HALF_UP)) @@ -46,8 +49,8 @@ class PartStudent(db.Model): id = db.Column(db.Integer, primary_key=True) final_part_mark = db.Column( db.Integer, - db.CheckConstraint("final_part_mark > -1"), - db.CheckConstraint("final_part_mark < 16"), + db.CheckConstraint(f"final_part_mark >= {MIN_MARK}"), + db.CheckConstraint(f"final_part_mark <= {MAX_MARK}"), nullable=True, ) @@ -497,21 +500,21 @@ class ExperimentMark(db.Model): oral_mark = db.Column( db.Integer, - db.CheckConstraint("oral_mark > -1"), - db.CheckConstraint("oral_mark < 16"), + db.CheckConstraint(f"oral_mark >= {MIN_MARK}"), + db.CheckConstraint(f"oral_mark <= {MIN_MARK}"), nullable=True, ) protocol_mark = db.Column( db.Integer, - db.CheckConstraint("protocol_mark > -1"), - db.CheckConstraint("protocol_mark < 16"), + db.CheckConstraint(f"oral_mark >= {MIN_MARK}"), + db.CheckConstraint(f"oral_mark <= {MIN_MARK}"), nullable=True, ) final_experiment_mark = db.Column( db.Integer, - db.CheckConstraint("protocol_mark > -1"), - db.CheckConstraint("protocol_mark < 16"), + db.CheckConstraint(f"oral_mark >= {MIN_MARK}"), + db.CheckConstraint(f"oral_mark <= {MIN_MARK}"), onupdate=final_experiment_mark_update, nullable=True, )