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

Add min and max mark as constants

This commit is contained in:
Mo 2022-04-12 01:44:53 +02:00
parent 0d28a3b090
commit 0ee5fcd52b
2 changed files with 17 additions and 12 deletions

View file

@ -11,6 +11,8 @@ from advlabdb import assistantSpace, db
from advlabdb.customClasses import SecureAssistantBaseView, SecureAssistantModelView from advlabdb.customClasses import SecureAssistantBaseView, SecureAssistantModelView
from advlabdb.exceptions import DataBaseException, ModelViewException from advlabdb.exceptions import DataBaseException, ModelViewException
from advlabdb.models import ( from advlabdb.models import (
MAX_MARK,
MIN_MARK,
Appointment, Appointment,
Assistant, Assistant,
Experiment, Experiment,
@ -91,8 +93,8 @@ class AssistantExperimentMarkView(SecureAssistantModelView):
"part_student.part": "Part", "part_student.part": "Part",
} }
column_descriptions = { column_descriptions = {
"oral_mark": "Between 0 and 15", "oral_mark": f"Between {MIN_MARK} and {MAX_MARK}",
"protocol_mark": "Between 0 and 15", "protocol_mark": f"Between {MIN_MARK} and {MAX_MARK}",
"final_experiment_mark": "Calculated automatically with oral and protocol marks and weightings", "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", "part_student.student.contact_email": "The preferred contact email address if entered by the student",
"assistant": "The last assistant who edited the mark", "assistant": "The last assistant who edited the mark",
@ -106,8 +108,8 @@ class AssistantExperimentMarkView(SecureAssistantModelView):
form_columns = column_editable_list form_columns = column_editable_list
form_args = { form_args = {
"oral_mark": {"validators": [NumberRange(0, 15)]}, "oral_mark": {"validators": [NumberRange(MIN_MARK, MAX_MARK)]},
"protocol_mark": {"validators": [NumberRange(0, 15)]}, "protocol_mark": {"validators": [NumberRange(MIN_MARK, MAX_MARK)]},
} }
column_default_sort = [("oral_mark", False), ("protocol_mark", False)] column_default_sort = [("oral_mark", False), ("protocol_mark", False)]

View file

@ -16,6 +16,9 @@ from advlabdb import db
from advlabdb.configUtils import getConfig from advlabdb.configUtils import getConfig
from advlabdb.exceptions import DataBaseException from advlabdb.exceptions import DataBaseException
MIN_MARK = 0
MAX_MARK = 15
def roundHalfUpToInt(number): def roundHalfUpToInt(number):
return int(Decimal(number).quantize(Decimal(0), rounding=ROUND_HALF_UP)) 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) id = db.Column(db.Integer, primary_key=True)
final_part_mark = db.Column( final_part_mark = db.Column(
db.Integer, db.Integer,
db.CheckConstraint("final_part_mark > -1"), db.CheckConstraint(f"final_part_mark >= {MIN_MARK}"),
db.CheckConstraint("final_part_mark < 16"), db.CheckConstraint(f"final_part_mark <= {MAX_MARK}"),
nullable=True, nullable=True,
) )
@ -497,21 +500,21 @@ class ExperimentMark(db.Model):
oral_mark = db.Column( oral_mark = db.Column(
db.Integer, db.Integer,
db.CheckConstraint("oral_mark > -1"), db.CheckConstraint(f"oral_mark >= {MIN_MARK}"),
db.CheckConstraint("oral_mark < 16"), db.CheckConstraint(f"oral_mark <= {MIN_MARK}"),
nullable=True, nullable=True,
) )
protocol_mark = db.Column( protocol_mark = db.Column(
db.Integer, db.Integer,
db.CheckConstraint("protocol_mark > -1"), db.CheckConstraint(f"oral_mark >= {MIN_MARK}"),
db.CheckConstraint("protocol_mark < 16"), db.CheckConstraint(f"oral_mark <= {MIN_MARK}"),
nullable=True, nullable=True,
) )
final_experiment_mark = db.Column( final_experiment_mark = db.Column(
db.Integer, db.Integer,
db.CheckConstraint("protocol_mark > -1"), db.CheckConstraint(f"oral_mark >= {MIN_MARK}"),
db.CheckConstraint("protocol_mark < 16"), db.CheckConstraint(f"oral_mark <= {MIN_MARK}"),
onupdate=final_experiment_mark_update, onupdate=final_experiment_mark_update,
nullable=True, nullable=True,
) )