From 8717f42bac0da1f768a65ce434cf95461c23a434 Mon Sep 17 00:00:00 2001 From: Mo8it Date: Sun, 11 Sep 2022 20:05:09 +0200 Subject: [PATCH] Remove active semester drop down menu --- advlabdb/adminModelViews.py | 3 +- advlabdb/assistantModelViews.py | 4 +-- advlabdb/model_dependent_funs.py | 36 ++++++++------------ advlabdb/templates/docs/assistant.jinja.html | 12 ++----- 4 files changed, 21 insertions(+), 34 deletions(-) diff --git a/advlabdb/adminModelViews.py b/advlabdb/adminModelViews.py index 7c8b12f..7ac74ad 100644 --- a/advlabdb/adminModelViews.py +++ b/advlabdb/adminModelViews.py @@ -69,7 +69,6 @@ from .database_import import importFromFile from .exceptions import ModelViewException from .model_dependent_funs import ( generate_new_password_field, - initActiveSemesterMenuLinks, mark_field, user_info_fields, ) @@ -1506,4 +1505,4 @@ def init_admin_model_views(app): adminSpace.add_view(AnalysisView(name="Analysis", url="analysis")) adminSpace.add_view(DocsView(name="Docs", url="docs")) - initActiveSemesterMenuLinks(adminSpace, app) + adminSpace.add_link(MenuLink(name="Logout", url="/logout")) diff --git a/advlabdb/assistantModelViews.py b/advlabdb/assistantModelViews.py index 33d8cc5..43ddaa1 100644 --- a/advlabdb/assistantModelViews.py +++ b/advlabdb/assistantModelViews.py @@ -1,6 +1,7 @@ from flask import flash, redirect, request, url_for from flask_admin import Admin as FlaskAdmin from flask_admin import expose +from flask_admin.menu import MenuLink from flask_admin.model.template import EndpointLinkRowAction from flask_login import current_user from flask_security.changeable import admin_change_password @@ -21,7 +22,6 @@ from .exceptions import ModelViewException from .forms import assistant_group_experiment_form_factory from .model_dependent_funs import ( generate_new_password_field, - initActiveSemesterMenuLinks, parse_selection_mark_field, user_info_fields, ) @@ -230,4 +230,4 @@ def init_assistant_model_views(app): assistantSpace.add_view(AssistantUserView(User, url="user")) assistantSpace.add_view(AssistantDocsView(name="Docs", url="docs")) - initActiveSemesterMenuLinks(assistantSpace, app) + assistantSpace.add_link(MenuLink(name="Logout", url="/logout")) diff --git a/advlabdb/model_dependent_funs.py b/advlabdb/model_dependent_funs.py index 302ba59..76e0940 100644 --- a/advlabdb/model_dependent_funs.py +++ b/advlabdb/model_dependent_funs.py @@ -4,40 +4,34 @@ Functions dependent on advlabdb.models. from functools import cache -from flask import flash -from flask_admin.menu import MenuLink +from flask import flash, url_for from flask_login import current_user +from markupsafe import Markup from wtforms.fields import BooleanField, IntegerField, SelectField, StringField from wtforms.validators import DataRequired, NumberRange, Optional from .models import MAX_MARK, MIN_MARK, Semester -def initActiveSemesterMenuLinks(space, app): - with app.app_context(): - try: - semesters = Semester.sortedSemestersStartingWithNewest() - for semester in semesters: - space.add_link( - MenuLink( - name=str(semester), - url="/set_semester" + "?semester_id=" + str(semester.id), - category="Active semester", - ) - ) - except Exception: - print( - "ERROR: The Semester table does not exist yet! Therefore, menu links could not be generated. You can ignore this error if you are just initializing the database." - ) - else: - space.add_link(MenuLink(name="Logout", url="/logout")) +def user_settings_url(): + if current_user.has_role("admin"): + role = "admin" + else: + role = "assistant" + + return url_for("main.index") + role + "/user/edit/?id=" + str(current_user.id) def active_semester_str(): active_semester = current_user.active_semester active_semester_str = str(active_semester) if active_semester != Semester.lastSemester(): - flash(f"You are in the old semester {active_semester_str}!", "warning") + flash( + Markup( + f"You are in the old semester {active_semester_str}! You should change your active semester in user settings." + ), + "warning", + ) return active_semester_str diff --git a/advlabdb/templates/docs/assistant.jinja.html b/advlabdb/templates/docs/assistant.jinja.html index a690e7a..b68da16 100644 --- a/advlabdb/templates/docs/assistant.jinja.html +++ b/advlabdb/templates/docs/assistant.jinja.html @@ -1,8 +1,3 @@ - -

Welcome

Welcome to this website, AdvLabDB, where you will be able to manage your lab @@ -91,8 +86,7 @@ assistant, your active semester should be the latest semester.

- If you see a warning that you are in an old semester, click on - Active semester and choose the latest semester. You should only work - in an old semester if there are still experiment marks to be set in the old - semester. + If you see a warning that you are in an old semester, then you should change + your active semester in the user settings. You should only work in an old + semester if there are still experiment marks to be set in the old semester.