mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-12-20 23:41:20 +00:00
Fixed customInit for GroupExperiment
This commit is contained in:
parent
91547a7487
commit
b2655e2023
2 changed files with 13 additions and 5 deletions
|
@ -5,7 +5,7 @@ from flask_admin.model.template import EndpointLinkRowAction
|
||||||
from flask_security import current_user, hash_password
|
from flask_security import current_user, hash_password
|
||||||
from sqlalchemy import func
|
from sqlalchemy import func
|
||||||
from wtforms import Form, BooleanField, SelectField, TextField, RadioField
|
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.contrib.sqla.fields import QuerySelectMultipleField, QuerySelectField
|
||||||
from flask_admin.helpers import get_form_data
|
from flask_admin.helpers import get_form_data
|
||||||
from wtforms.fields.html5 import DateField
|
from wtforms.fields.html5 import DateField
|
||||||
|
@ -40,14 +40,14 @@ from advlabdb.exceptions import ModelViewValidatorException
|
||||||
class UserView(SecureModelView):
|
class UserView(SecureModelView):
|
||||||
column_list = ["email", "active", "roles", "assistant", "active_semester"]
|
column_list = ["email", "active", "roles", "assistant", "active_semester"]
|
||||||
column_searchable_list = ["email"]
|
column_searchable_list = ["email"]
|
||||||
column_filters = ["active"]
|
column_filters = ["active", "active_semester"]
|
||||||
form_columns = ["email", "active", "roles"]
|
form_columns = ["email", "active", "roles", "active_semester"]
|
||||||
column_editable_list = ["active"]
|
column_editable_list = ["active"]
|
||||||
|
|
||||||
form_args = {
|
form_args = {
|
||||||
"email": {"validators": [Email()]},
|
"email": {"validators": [Email()]},
|
||||||
"active": {"default": True},
|
"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):
|
def create_model(self, form):
|
||||||
|
@ -340,6 +340,10 @@ class ExperimentView(SecureModelView):
|
||||||
]
|
]
|
||||||
column_editable_list = ["active"]
|
column_editable_list = ["active"]
|
||||||
|
|
||||||
|
form_excluded_columns = ["semester_experiments"]
|
||||||
|
|
||||||
|
form_args = {"wiki_link": {"validators": [URL()]}}
|
||||||
|
|
||||||
|
|
||||||
class SemesterExperimentView(SecureModelView):
|
class SemesterExperimentView(SecureModelView):
|
||||||
column_list = ["experiment", "semester", "assistants"]
|
column_list = ["experiment", "semester", "assistants"]
|
||||||
|
|
|
@ -101,7 +101,11 @@ class GroupExperiment(db.Model):
|
||||||
student = partStudent.student
|
student = partStudent.student
|
||||||
for partStudent in student.part_students:
|
for partStudent in student.part_students:
|
||||||
for experimentMark in partStudent.experiment_marks:
|
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(
|
raise Exception(
|
||||||
f"{student} has already done {semester_experiment.experiment} in {partStudent.part} and had {experimentMark}!"
|
f"{student} has already done {semester_experiment.experiment} in {partStudent.part} and had {experimentMark}!"
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue