1
0
Fork 0
mirror of https://codeberg.org/Mo8it/AdvLabDB.git synced 2024-11-08 21:21:06 +00:00

Done SemesterExperimentView

This commit is contained in:
Mo 2021-07-29 00:31:43 +02:00
parent d92fd2e454
commit 6ac4ab32e0

View file

@ -312,12 +312,53 @@ class ExperimentView(SecureModelView):
form_args = {"wiki_link": {"validators": [URL()]}} form_args = {"wiki_link": {"validators": [URL()]}}
def assistantQueryFactory():
return Assistant.query.filter(Assistant.user_id.in_([user.id for user in User.query.filter(User.active == True)]))
class SemesterExperimentView(SecureModelView): class SemesterExperimentView(SecureModelView):
column_list = ["experiment", "semester", "assistants"] class CreateForm(Form):
def experimentQueryFactory():
return Experiment.query.filter(Experiment.active == True)
experiment = QuerySelectField(
"Experiment",
query_factory=experimentQueryFactory,
validators=[DataRequired()],
allow_blank=True,
blank_text="-",
)
assistants = QuerySelectMultipleField("Assistants", query_factory=assistantQueryFactory)
form = CreateForm
can_view_details = True
column_list = ["experiment", "assistants", "semester"]
column_details_list = column_list + ["group_experiments"]
def queryFilter(self): def queryFilter(self):
return SemesterExperiment.semester == userActiveSemester() return SemesterExperiment.semester == userActiveSemester()
def create_model(self, form):
try:
model = SemesterExperiment(
semester=userActiveSemester(), experiment=form.experiment.data, assistants=form.assistants.data
)
self.session.add(model)
self.on_model_change(form, model, True)
self.session.commit()
except Exception as ex:
flash(str(ex), "error")
self.session.rollback()
else:
self.after_model_change(form, model, True)
return model
class AssistantView(SecureModelView): class AssistantView(SecureModelView):
can_view_details = True can_view_details = True
@ -334,10 +375,6 @@ class AssistantView(SecureModelView):
form_excluded_columns = ["experiment_marks"] form_excluded_columns = ["experiment_marks"]
def assistantQueryFactory():
return Assistant.query.filter(Assistant.user_id.in_([user.id for user in User.query.filter(User.active == True)]))
assistantBlankText = "Auto assign if experiment has only one assistant" assistantBlankText = "Auto assign if experiment has only one assistant"
@ -382,6 +419,7 @@ class GroupExperimentView(SecureModelView):
form = CreateForm form = CreateForm
can_edit = False can_edit = False
column_list = ["group", "semester_experiment", "appointments", "experiment_marks"] column_list = ["group", "semester_experiment", "appointments", "experiment_marks"]
column_filters = ["group", "semester_experiment.experiment", "appointments"] column_filters = ["group", "semester_experiment.experiment", "appointments"]