mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-11-08 21:21:06 +00:00
Done SemesterExperimentView
This commit is contained in:
parent
d92fd2e454
commit
6ac4ab32e0
1 changed files with 43 additions and 5 deletions
|
@ -312,12 +312,53 @@ class ExperimentView(SecureModelView):
|
|||
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):
|
||||
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):
|
||||
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):
|
||||
can_view_details = True
|
||||
|
@ -334,10 +375,6 @@ class AssistantView(SecureModelView):
|
|||
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"
|
||||
|
||||
|
||||
|
@ -382,6 +419,7 @@ class GroupExperimentView(SecureModelView):
|
|||
form = CreateForm
|
||||
|
||||
can_edit = False
|
||||
|
||||
column_list = ["group", "semester_experiment", "appointments", "experiment_marks"]
|
||||
column_filters = ["group", "semester_experiment.experiment", "appointments"]
|
||||
|
||||
|
|
Loading…
Reference in a new issue