From b2655e20234e0d5fe10987ccbf506dac8b2a7508 Mon Sep 17 00:00:00 2001 From: Mo8it Date: Tue, 13 Jul 2021 18:41:00 +0200 Subject: [PATCH] Fixed customInit for GroupExperiment --- advlabdb/modelViews.py | 12 ++++++++---- advlabdb/models.py | 6 +++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/advlabdb/modelViews.py b/advlabdb/modelViews.py index e69dbcd..2f32309 100644 --- a/advlabdb/modelViews.py +++ b/advlabdb/modelViews.py @@ -5,7 +5,7 @@ from flask_admin.model.template import EndpointLinkRowAction from flask_security import current_user, hash_password from sqlalchemy import func from wtforms import Form, BooleanField, SelectField, TextField, RadioField -from wtforms.validators import DataRequired, Email, Optional +from wtforms.validators import DataRequired, Email, Optional, URL from flask_admin.contrib.sqla.fields import QuerySelectMultipleField, QuerySelectField from flask_admin.helpers import get_form_data from wtforms.fields.html5 import DateField @@ -40,14 +40,14 @@ from advlabdb.exceptions import ModelViewValidatorException class UserView(SecureModelView): column_list = ["email", "active", "roles", "assistant", "active_semester"] column_searchable_list = ["email"] - column_filters = ["active"] - form_columns = ["email", "active", "roles"] + column_filters = ["active", "active_semester"] + form_columns = ["email", "active", "roles", "active_semester"] column_editable_list = ["active"] form_args = { "email": {"validators": [Email()]}, "active": {"default": True}, - "roles": {"validators": [DataRequired(message="A role is required!")]}, + "roles": {"default": [Role.query.filter(Role.name == "assistant").first()], "validators": [DataRequired()]}, } def create_model(self, form): @@ -340,6 +340,10 @@ class ExperimentView(SecureModelView): ] column_editable_list = ["active"] + form_excluded_columns = ["semester_experiments"] + + form_args = {"wiki_link": {"validators": [URL()]}} + class SemesterExperimentView(SecureModelView): column_list = ["experiment", "semester", "assistants"] diff --git a/advlabdb/models.py b/advlabdb/models.py index 8d4e067..75b8eb7 100644 --- a/advlabdb/models.py +++ b/advlabdb/models.py @@ -101,7 +101,11 @@ class GroupExperiment(db.Model): student = partStudent.student for partStudent in student.part_students: for experimentMark in partStudent.experiment_marks: - if experimentMark.group_experiment.semester_experiment.experiment == semester_experiment.experiment: + if ( + (experimentMark.oral_mark or experimentMark.protocol_mark) + and experimentMark.group_experiment.semester_experiment.experiment + == semester_experiment.experiment + ): raise Exception( f"{student} has already done {semester_experiment.experiment} in {partStudent.part} and had {experimentMark}!" )