mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-11-08 21:21:06 +00:00
Remove active semester drop down menu
This commit is contained in:
parent
8846a867f5
commit
8717f42bac
4 changed files with 21 additions and 34 deletions
|
@ -69,7 +69,6 @@ from .database_import import importFromFile
|
||||||
from .exceptions import ModelViewException
|
from .exceptions import ModelViewException
|
||||||
from .model_dependent_funs import (
|
from .model_dependent_funs import (
|
||||||
generate_new_password_field,
|
generate_new_password_field,
|
||||||
initActiveSemesterMenuLinks,
|
|
||||||
mark_field,
|
mark_field,
|
||||||
user_info_fields,
|
user_info_fields,
|
||||||
)
|
)
|
||||||
|
@ -1506,4 +1505,4 @@ def init_admin_model_views(app):
|
||||||
adminSpace.add_view(AnalysisView(name="Analysis", url="analysis"))
|
adminSpace.add_view(AnalysisView(name="Analysis", url="analysis"))
|
||||||
adminSpace.add_view(DocsView(name="Docs", url="docs"))
|
adminSpace.add_view(DocsView(name="Docs", url="docs"))
|
||||||
|
|
||||||
initActiveSemesterMenuLinks(adminSpace, app)
|
adminSpace.add_link(MenuLink(name="Logout", url="/logout"))
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
from flask import flash, redirect, request, url_for
|
from flask import flash, redirect, request, url_for
|
||||||
from flask_admin import Admin as FlaskAdmin
|
from flask_admin import Admin as FlaskAdmin
|
||||||
from flask_admin import expose
|
from flask_admin import expose
|
||||||
|
from flask_admin.menu import MenuLink
|
||||||
from flask_admin.model.template import EndpointLinkRowAction
|
from flask_admin.model.template import EndpointLinkRowAction
|
||||||
from flask_login import current_user
|
from flask_login import current_user
|
||||||
from flask_security.changeable import admin_change_password
|
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 .forms import assistant_group_experiment_form_factory
|
||||||
from .model_dependent_funs import (
|
from .model_dependent_funs import (
|
||||||
generate_new_password_field,
|
generate_new_password_field,
|
||||||
initActiveSemesterMenuLinks,
|
|
||||||
parse_selection_mark_field,
|
parse_selection_mark_field,
|
||||||
user_info_fields,
|
user_info_fields,
|
||||||
)
|
)
|
||||||
|
@ -230,4 +230,4 @@ def init_assistant_model_views(app):
|
||||||
assistantSpace.add_view(AssistantUserView(User, url="user"))
|
assistantSpace.add_view(AssistantUserView(User, url="user"))
|
||||||
assistantSpace.add_view(AssistantDocsView(name="Docs", url="docs"))
|
assistantSpace.add_view(AssistantDocsView(name="Docs", url="docs"))
|
||||||
|
|
||||||
initActiveSemesterMenuLinks(assistantSpace, app)
|
assistantSpace.add_link(MenuLink(name="Logout", url="/logout"))
|
||||||
|
|
|
@ -4,40 +4,34 @@ Functions dependent on advlabdb.models.
|
||||||
|
|
||||||
from functools import cache
|
from functools import cache
|
||||||
|
|
||||||
from flask import flash
|
from flask import flash, url_for
|
||||||
from flask_admin.menu import MenuLink
|
|
||||||
from flask_login import current_user
|
from flask_login import current_user
|
||||||
|
from markupsafe import Markup
|
||||||
from wtforms.fields import BooleanField, IntegerField, SelectField, StringField
|
from wtforms.fields import BooleanField, IntegerField, SelectField, StringField
|
||||||
from wtforms.validators import DataRequired, NumberRange, Optional
|
from wtforms.validators import DataRequired, NumberRange, Optional
|
||||||
|
|
||||||
from .models import MAX_MARK, MIN_MARK, Semester
|
from .models import MAX_MARK, MIN_MARK, Semester
|
||||||
|
|
||||||
|
|
||||||
def initActiveSemesterMenuLinks(space, app):
|
def user_settings_url():
|
||||||
with app.app_context():
|
if current_user.has_role("admin"):
|
||||||
try:
|
role = "admin"
|
||||||
semesters = Semester.sortedSemestersStartingWithNewest()
|
else:
|
||||||
for semester in semesters:
|
role = "assistant"
|
||||||
space.add_link(
|
|
||||||
MenuLink(
|
return url_for("main.index") + role + "/user/edit/?id=" + str(current_user.id)
|
||||||
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 active_semester_str():
|
def active_semester_str():
|
||||||
active_semester = current_user.active_semester
|
active_semester = current_user.active_semester
|
||||||
active_semester_str = str(active_semester)
|
active_semester_str = str(active_semester)
|
||||||
if active_semester != Semester.lastSemester():
|
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 <a href='{ user_settings_url() }'>user settings</a>."
|
||||||
|
),
|
||||||
|
"warning",
|
||||||
|
)
|
||||||
|
|
||||||
return active_semester_str
|
return active_semester_str
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,3 @@
|
||||||
<div class="alert alert-warning" role="alert">
|
|
||||||
Changes have been done to the web interface. Read the section
|
|
||||||
<a href="#_group_experiment">Group Experiment</a> for more information.
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<h2>Welcome</h2>
|
<h2>Welcome</h2>
|
||||||
<p>
|
<p>
|
||||||
Welcome to this website, AdvLabDB, where you will be able to manage your lab
|
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.
|
assistant, your active semester should be the latest semester.
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
If you see a warning that you are in an old semester, click on
|
If you see a warning that you are in an old semester, then you should change
|
||||||
<em>Active semester</em> and choose the latest semester. You should only work
|
your active semester in the user settings. You should only work in an old
|
||||||
in an old semester if there are still experiment marks to be set in the old
|
semester if there are still experiment marks to be set in the old semester.
|
||||||
semester.
|
|
||||||
</p>
|
</p>
|
||||||
|
|
Loading…
Reference in a new issue