From 8da20c23c3414ab17501e5c9180a13daf9f00ea3 Mon Sep 17 00:00:00 2001 From: Mo8it Date: Thu, 29 Jul 2021 20:03:41 +0200 Subject: [PATCH] Added Jinja macros --- advlabdb/__init__.py | 1 + advlabdb/modelViews.py | 2 ++ advlabdb/routes.py | 2 +- advlabdb/templates/admin_create.html | 3 ++- advlabdb/templates/admin_edit.html | 3 ++- advlabdb/templates/admin_index.html | 3 ++- advlabdb/templates/admin_list.html | 3 ++- advlabdb/templates/macros.html | 4 ++++ 8 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 advlabdb/templates/macros.html diff --git a/advlabdb/__init__.py b/advlabdb/__init__.py index 37e3bff..d8baa11 100644 --- a/advlabdb/__init__.py +++ b/advlabdb/__init__.py @@ -45,3 +45,4 @@ except Exception as ex: print( "\nYou are probably initializing the database with a script. If not, then you have to worry about not being able to import in __init__.py!\n" ) + print(str(ex)) diff --git a/advlabdb/modelViews.py b/advlabdb/modelViews.py index cddfaab..0cfe2ee 100644 --- a/advlabdb/modelViews.py +++ b/advlabdb/modelViews.py @@ -38,6 +38,8 @@ from advlabdb.exceptions import ModelViewException class UserView(SecureModelView): + can_view_details = True + column_list = ["email", "active", "roles", "assistant", "active_semester"] column_searchable_list = ["email"] column_filters = ["active", "active_semester", "assistant"] diff --git a/advlabdb/routes.py b/advlabdb/routes.py index 19f15e7..4d752ac 100644 --- a/advlabdb/routes.py +++ b/advlabdb/routes.py @@ -7,7 +7,7 @@ from advlabdb.utils import setUserActiveSemester, userActiveSemester @app.context_processor def util_processor(): - return dict(userActiveSemester=userActiveSemester) + return dict(userActiveSemester=userActiveSemester, current_user=current_user) @app.route("/") diff --git a/advlabdb/templates/admin_create.html b/advlabdb/templates/admin_create.html index eccc7f6..101410e 100644 --- a/advlabdb/templates/admin_create.html +++ b/advlabdb/templates/admin_create.html @@ -1,6 +1,7 @@ +{% from "macros.html" import information %} {% extends "admin/model/create.html" %} {% block body %} -User's active semester: {{userActiveSemester().repr()}} +{{ information(current_user, userActiveSemester, role="admin") }} {{super()}} {% endblock %} \ No newline at end of file diff --git a/advlabdb/templates/admin_edit.html b/advlabdb/templates/admin_edit.html index 66b2c8d..5085861 100644 --- a/advlabdb/templates/admin_edit.html +++ b/advlabdb/templates/admin_edit.html @@ -1,6 +1,7 @@ +{% from "macros.html" import information %} {% extends "admin/model/edit.html" %} {% block body %} -User's active semester: {{userActiveSemester().repr()}} +{{ information(current_user, userActiveSemester, role="admin") }} {{super()}} {% endblock %} \ No newline at end of file diff --git a/advlabdb/templates/admin_index.html b/advlabdb/templates/admin_index.html index 9c6dd12..e650c14 100644 --- a/advlabdb/templates/admin_index.html +++ b/advlabdb/templates/admin_index.html @@ -1,7 +1,8 @@ +{% from "macros.html" import information %} {% extends "admin/index.html" %} {% block body %} -User's active semester: {{userActiveSemester(flashWarning=True).repr()}} +{{ information(current_user, userActiveSemester, role="admin") }}

Welcome back, commander!

{{super()}} {% endblock %} \ No newline at end of file diff --git a/advlabdb/templates/admin_list.html b/advlabdb/templates/admin_list.html index 1401d0b..22fea54 100644 --- a/advlabdb/templates/admin_list.html +++ b/advlabdb/templates/admin_list.html @@ -1,6 +1,7 @@ +{% from "macros.html" import information %} {% extends "admin/model/list.html" %} {% block body %} -User's active semester: {{userActiveSemester(flashWarning=True).repr()}} +{{ information(current_user, userActiveSemester, role="admin") }} {{super()}} {% endblock %} \ No newline at end of file diff --git a/advlabdb/templates/macros.html b/advlabdb/templates/macros.html new file mode 100644 index 0000000..190837d --- /dev/null +++ b/advlabdb/templates/macros.html @@ -0,0 +1,4 @@ +{% macro information(current_user, userActiveSemester, role) %} +User: {{current_user.repr()}}; Active +semester: {{userActiveSemester(flashWarning=True).repr()}}. +{% endmacro %} \ No newline at end of file