mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-09-19 18:31:16 +00:00
Add user settings
This commit is contained in:
parent
5d0f99a381
commit
cf8279616e
6 changed files with 81 additions and 59 deletions
|
@ -1524,8 +1524,6 @@ class DocsView(SecureAdminBaseView):
|
|||
|
||||
|
||||
def init_admin_model_views(app):
|
||||
adminSpace.init_app(app)
|
||||
|
||||
adminSpace.add_view(StudentView(Student, url="student"))
|
||||
adminSpace.add_view(PartStudentView(PartStudent, url="part_student"))
|
||||
adminSpace.add_view(GroupView(Group, url="group"))
|
||||
|
@ -1545,4 +1543,7 @@ def init_admin_model_views(app):
|
|||
adminSpace.add_view(AnalysisView(name="Analysis", url="analysis"))
|
||||
adminSpace.add_view(DocsView(name="Docs", url="docs"))
|
||||
|
||||
adminSpace.add_link(MenuLink(name="User settings", url="/user-settings"))
|
||||
adminSpace.add_link(MenuLink(name="Logout", url="/logout"))
|
||||
|
||||
adminSpace.init_app(app)
|
||||
|
|
|
@ -27,7 +27,6 @@ from .model_dependent_funs import (
|
|||
generate_new_password_field,
|
||||
parse_selection_mark_field,
|
||||
user_info_fields,
|
||||
user_settings_url,
|
||||
)
|
||||
from .model_independent_funs import randomPassword, reportBadAttempt
|
||||
from .models import Assistant, GroupExperiment, Semester, SemesterExperiment, User, db
|
||||
|
@ -53,7 +52,7 @@ class AssistantGroupExperimentView(SecureAssistantModelView):
|
|||
if not semester_changed:
|
||||
flash(
|
||||
Markup(
|
||||
f"Active semester {active_semester} is set as done. Therefore, you are not allowed to view or edit any marks in this semester. You should change your active semester in <a href='{ user_settings_url() }'>user settings</a> if possible."
|
||||
f"Active semester {active_semester} is set as done. Therefore, you are not allowed to view or edit any marks in this semester. You should change your active semester in <a href='/user-settings'>user settings</a> if possible."
|
||||
),
|
||||
"danger",
|
||||
)
|
||||
|
@ -131,7 +130,8 @@ class AssistantGroupExperimentView(SecureAssistantModelView):
|
|||
|
||||
if group_experiment not in self.get_query():
|
||||
reportBadAttempt("Assistant {current_user} tried to edit {group_experiment}")
|
||||
raise ModelViewException("Unauthorized action!")
|
||||
self.handle_view_exception(ModelViewException("Unauthorized action!"))
|
||||
return redirect(self.url)
|
||||
|
||||
form, appointments, experiment_marks = assistant_group_experiment_form_factory(current_user, group_experiment)
|
||||
|
||||
|
@ -261,10 +261,14 @@ class AssistantDocsView(SecureAssistantBaseView):
|
|||
|
||||
|
||||
def init_assistant_model_views(app):
|
||||
assistantSpace.init_app(app)
|
||||
|
||||
assistantSpace.add_view(AssistantGroupExperimentView(GroupExperiment, url="group_experiment"))
|
||||
assistantSpace.add_view(AssistantUserView(User, url="user"))
|
||||
assistantSpace.add_view(AssistantDocsView(name="Docs", url="docs"))
|
||||
|
||||
# Don't add to menu
|
||||
# Has to be placed before assistantSpace.init_app
|
||||
assistantSpace._views.append(AssistantUserView(User, url="user"))
|
||||
|
||||
assistantSpace.add_link(MenuLink(name="User settings", url="/user-settings"))
|
||||
assistantSpace.add_link(MenuLink(name="Logout", url="/logout"))
|
||||
|
||||
assistantSpace.init_app(app)
|
||||
|
|
|
@ -13,22 +13,13 @@ from wtforms.validators import DataRequired, NumberRange, Optional
|
|||
from .models import MAX_MARK, MIN_MARK, Semester
|
||||
|
||||
|
||||
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(
|
||||
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>."
|
||||
f"You are in the old semester {active_semester_str}! You should change your active semester in <a href='/user-settings'>user settings</a>."
|
||||
),
|
||||
"warning",
|
||||
)
|
||||
|
|
|
@ -48,3 +48,16 @@ def post_login():
|
|||
url = url_for(endpoint_base + ".index")
|
||||
|
||||
return redirect(url)
|
||||
|
||||
|
||||
@bp.route("/user-settings")
|
||||
@auth_required()
|
||||
def user_settings():
|
||||
if current_user.has_role("admin"):
|
||||
role = "admin"
|
||||
else:
|
||||
role = "assistant"
|
||||
|
||||
url = url_for("main.index") + role + "/user/edit/?id=" + str(current_user.id)
|
||||
|
||||
return redirect(url)
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
<h3>Home</h3>
|
||||
<p>
|
||||
This is your home page. Here, you currently only find the number of
|
||||
This is your home page. Here, you find the number of
|
||||
<strong>missing</strong> final experiment marks for the experiments that you
|
||||
are assigned to. At the latest at the end of the semester, this number should
|
||||
be 0. A number higher than 0 means that some oral and/or protocol marks are
|
||||
|
@ -21,7 +21,7 @@
|
|||
and protocol marks of an experiment are set.
|
||||
</p>
|
||||
|
||||
<h3 id="_group_experiment">Group Experiment</h3>
|
||||
<h3>Group Experiment</h3>
|
||||
<p>
|
||||
This is the most important menu item. Here, you see all pairs of experiments
|
||||
and groups that you are responsible for. If a value in the column
|
||||
|
@ -48,38 +48,25 @@
|
|||
Oral and protocol marks are between 0 and 15!
|
||||
</div>
|
||||
<p>
|
||||
After editing appointment date(s) or experiment marks, click on the
|
||||
<em>Save</em> button to save the changes.
|
||||
After editing appointment date(s) or experiment marks, click on
|
||||
<em>Save</em> to save the changes.
|
||||
</p>
|
||||
<p>
|
||||
The changes are lost if you don't click on <em>Save</em>. Therefore, if you
|
||||
want to discard the changes, just click on the back button of your browser.
|
||||
</p>
|
||||
|
||||
<h3>User</h3>
|
||||
<p>
|
||||
Here, you find a table with only one row which is you as a user. Make sure
|
||||
that the fields <em>Phone Number</em>, <em>Mobile Phone Number</em>,
|
||||
<em>Building</em> and <em>Room</em> are filled and up to date, especially if
|
||||
you are a new assistant. To edit these fields, click on the pen icon at the
|
||||
left of the single entry in the table. After editing, click on <em>Save</em>.
|
||||
</p>
|
||||
<p>
|
||||
You can generate a new random password by clicking on the pen icon, checking
|
||||
the corresponding checkbox and then clicking on
|
||||
<em>Save</em>. You will be then logged out. Your new password is displayed
|
||||
above the login fields. Make sure that you save the password in a safe place.
|
||||
Using a free open source password manager like
|
||||
<a href="https://bitwarden.com/" target="_blank" rel="noopener">Bitwarden</a>
|
||||
or
|
||||
<a href="https://keepassxc.org/" target="_blank" rel="noopener">KeepassXC</a>
|
||||
is recommended.
|
||||
</p>
|
||||
|
||||
<h3>Docs</h3>
|
||||
<p>This is a link which leads you to this page.</p>
|
||||
|
||||
<h3>Active semester</h3>
|
||||
<h3>User settings</h3>
|
||||
<p>
|
||||
In the user settings, You can change your active semester, user information
|
||||
and password. Don't forget to click on <em>Save</em> after changing any
|
||||
option.
|
||||
</p>
|
||||
|
||||
<h4>Active semester</h4>
|
||||
<p>
|
||||
An active semester is the semester you are working in. All shown experiment
|
||||
marks and appointments are in your active semester. By default as a new
|
||||
|
@ -90,3 +77,22 @@
|
|||
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.
|
||||
</p>
|
||||
|
||||
<h4>User information</h4>
|
||||
<p>
|
||||
Make sure that the fields <em>Phone Number</em>, <em>Mobile Phone Number</em>,
|
||||
<em>Building</em> and <em>Room</em> are filled and up to date, especially if
|
||||
you are a new assistant.
|
||||
</p>
|
||||
|
||||
<h4>Password</h4>
|
||||
<p>
|
||||
You can generate a new random password by checking the corresponding checkbox
|
||||
and then clicking on <em>Save</em>. You will be then logged out. Your new
|
||||
password is displayed above the login fields. Make sure that you save the
|
||||
password in a safe place. Using a free open source password manager like
|
||||
<a href="https://bitwarden.com/" target="_blank" rel="noopener">Bitwarden</a>
|
||||
or
|
||||
<a href="https://keepassxc.org/" target="_blank" rel="noopener">KeepassXC</a>
|
||||
is recommended.
|
||||
</p>
|
||||
|
|
|
@ -1,18 +1,25 @@
|
|||
{% macro information(current_user, active_semester_str, role) %}
|
||||
User:
|
||||
<a
|
||||
href="{{ url_for('main.index') }}{{ role }}/user/edit/?id={{ current_user.id }}"
|
||||
>{{ current_user }}</a>
|
||||
| Active semester: {{ active_semester_str() }}
|
||||
{% if (role == "admin") and (current_user.has_role("assistant")) %}
|
||||
|
|
||||
<a
|
||||
href="{{ url_for('main.index') }}assistant"
|
||||
>Assistant space</a>.
|
||||
{% elif (role == "assistant") and (current_user.has_role("admin")) %}
|
||||
|
|
||||
<a
|
||||
href="{{ url_for('main.index') }}admin"
|
||||
>Admin space</a>.
|
||||
{% endif %}
|
||||
<div class="row" style="text-align: center;">
|
||||
<div class="col">
|
||||
User: {{ current_user }}
|
||||
</div>
|
||||
|
||||
<div class="col">
|
||||
Active semester: {{ active_semester_str() }}
|
||||
</div>
|
||||
|
||||
{% if (role == "admin") and (current_user.has_role("assistant")) %}
|
||||
<div class="col">
|
||||
<a
|
||||
href="{{ url_for('main.index') }}assistant"
|
||||
>Assistant space</a>
|
||||
</div>
|
||||
{% elif (role == "assistant") and (current_user.has_role("admin")) %}
|
||||
<div class="col">
|
||||
<a
|
||||
href="{{ url_for('main.index') }}admin"
|
||||
>Admin space</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endmacro %}
|
||||
|
|
Loading…
Reference in a new issue