diff --git a/advlabdb/adminModelViews.py b/advlabdb/adminModelViews.py index 1bac562..548de33 100644 --- a/advlabdb/adminModelViews.py +++ b/advlabdb/adminModelViews.py @@ -690,13 +690,10 @@ class ExperimentMarkView(SecureAdminModelView): blank_text="-", ) - markChoices = [(-1, "-")] + list(zip(range(16)[::-1], range(16)[::-1])) - - oral_mark = SelectField("Oral Mark", choices=markChoices, coerce=int) - protocol_mark = SelectField("Protocol Mark", choices=markChoices, coerce=int) - form = CreateForm + can_edit = False + column_descriptions = { "oral_mark": "Between 0 and 15", "protocol_mark": "Between 0 and 15", @@ -731,35 +728,12 @@ class ExperimentMarkView(SecureAdminModelView): ) """ - def checkForm(form): - if form.oral_mark and form.oral_mark.data == -1: - form.oral_mark.data = None - - if form.protocol_mark and form.protocol_mark.data == -1: - form.protocol_mark.data = None - - return form - - def create_model(self, form): - form = ExperimentMarkView.checkForm(form) - - model = super().create_model(form) - - if model and (model.oral_mark or model.protocol_mark): - try: - model.edited_by_admin = True - - self.session.commit() - except Exception as ex: - flash(str(ex), "error") - - self.session.rollback() - - return model + def customCreateModel(self, form): + return ExperimentMark.customInit( + part_student=form.part_student.data, group_experiment=form.group_experiment.data + ) def update_model(self, form, model): - form = ExperimentMarkView.checkForm(form) - if (form.oral_mark and form.oral_mark.data != model.oral_mark) or ( form.protocol_mark and form.protocol_mark.data != model.protocol_mark ): diff --git a/advlabdb/models.py b/advlabdb/models.py index 84d09c9..6e00f72 100644 --- a/advlabdb/models.py +++ b/advlabdb/models.py @@ -294,7 +294,7 @@ class Appointment(db.Model): semesterExperimentAssistants = semesterExperiment.assistants if not semesterExperimentAssistants: - raise Exception(f"{semesterExperiment} has no assistants yet!") + raise Exception(f"{semesterExperiment} does not have assistants yet!") if assistant: if assistant not in semesterExperimentAssistants: @@ -423,6 +423,15 @@ class ExperimentMark(db.Model): __table_args__ = (db.UniqueConstraint(part_student_id, group_experiment_id),) + def customInit(part_student, group_experiment): + if not part_student.group: + raise DataBaseException("The part student does not have a group yet!") + else: + if group_experiment not in part_student.group.group_experiments: + raise DataBaseException("The group of the part student does not have the given group experiment!") + + return ExperimentMark(part_student=part_student, group_experiment=group_experiment) + def repr(self): return f"Oral {self.oral_mark}; Prot {self.protocol_mark}"