1
0
Fork 0
mirror of https://codeberg.org/Mo8it/AdvLabDB.git synced 2024-12-20 23:41:20 +00:00

Done UserView and fixed user filter for AssistantView

This commit is contained in:
Mo 2021-07-29 17:37:15 +02:00
parent 6ee368d0ef
commit 8bf415220d

View file

@ -40,7 +40,7 @@ from advlabdb.exceptions import ModelViewException
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", "active_semester"] column_filters = ["active", "active_semester", "assistant"]
form_columns = ["email", "active", "roles", "active_semester"] form_columns = ["email", "active", "roles", "active_semester"]
column_editable_list = ["active"] column_editable_list = ["active"]
@ -61,7 +61,9 @@ class UserView(SecureModelView):
flash("You have registered a new admin!", "danger") flash("You have registered a new admin!", "danger")
try: 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.on_model_change(form, model, True)
self.session.commit() self.session.commit()
@ -367,6 +369,9 @@ class SemesterExperimentView(SecureModelView):
class AssistantView(SecureModelView): class AssistantView(SecureModelView):
def assistantUserQueryFactory():
return User.query.filter(User.roles.any(Role.name == "assistant"))
can_view_details = True can_view_details = True
column_list = ["first_name", "last_name", "user", "semester_experiments"] 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_searchable_list = ["first_name", "last_name", "user.email"]
column_filters = ["user.active"] 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" assistantBlankText = "Auto assign if experiment has only one assistant"