diff --git a/advlabdb/modelViews.py b/advlabdb/modelViews.py index 6bf9280..cddfaab 100644 --- a/advlabdb/modelViews.py +++ b/advlabdb/modelViews.py @@ -40,7 +40,7 @@ from advlabdb.exceptions import ModelViewException class UserView(SecureModelView): column_list = ["email", "active", "roles", "assistant", "active_semester"] column_searchable_list = ["email"] - column_filters = ["active", "active_semester"] + column_filters = ["active", "active_semester", "assistant"] form_columns = ["email", "active", "roles", "active_semester"] column_editable_list = ["active"] @@ -61,7 +61,9 @@ class UserView(SecureModelView): flash("You have registered a new admin!", "danger") try: - model = user_datastore.create_user(email=email, password=passwordHash, roles=roles) + model = user_datastore.create_user( + email=email, password=passwordHash, roles=roles, active_semester=form.active_semester.data + ) self.on_model_change(form, model, True) self.session.commit() @@ -367,6 +369,9 @@ class SemesterExperimentView(SecureModelView): class AssistantView(SecureModelView): + def assistantUserQueryFactory(): + return User.query.filter(User.roles.any(Role.name == "assistant")) + can_view_details = True column_list = ["first_name", "last_name", "user", "semester_experiments"] @@ -380,7 +385,17 @@ class AssistantView(SecureModelView): ] column_searchable_list = ["first_name", "last_name", "user.email"] column_filters = ["user.active"] - form_excluded_columns = ["experiment_marks", "appointments", "semester_experiments"] + form_excluded_columns = ["experiment_marks", "appointments", "semester_experiments", "user"] + + form_extra_fields = { + "user": QuerySelectField( + "User", + query_factory=assistantUserQueryFactory, + validators=[DataRequired()], + allow_blank=True, + blank_text="-", + ) + } assistantBlankText = "Auto assign if experiment has only one assistant"