1
0
Fork 0
mirror of https://codeberg.org/Mo8it/AdvLabDB.git synced 2024-11-08 21:21:06 +00:00

Fix bug for user that are not logged in

This commit is contained in:
Mo 2022-05-17 01:28:50 +02:00
parent 2236edb8aa
commit 6c268c3bb5
18 changed files with 32 additions and 23 deletions

View file

@ -67,3 +67,12 @@ def reportBadAttempt(message):
def get_count(table):
return db.session.scalar(select(func.count()).select_from(table))
def active_semester_repr():
active_semester = current_user.active_semester
repr = active_semester.repr()
if active_semester != lastSemester():
flash(f"You are in the old semester {repr}!", "warning")
return repr

View file

@ -2,17 +2,17 @@ from flask import flash, redirect, render_template, request, url_for
from flask_security import auth_required, current_user, roles_accepted, roles_required
from . import app, db
from .model_dependent_funs import lastSemester, setUserActiveSemester
from .model_dependent_funs import (
active_semester_repr,
lastSemester,
setUserActiveSemester,
)
from .models import Semester
@app.context_processor
def util_processor():
active_semester = current_user.active_semester
if active_semester != lastSemester():
flash(f"You are in the old semester {current_user.active_semester.repr()}!", "warning")
return dict(active_semester=active_semester, current_user=current_user)
return dict(active_semester_repr=active_semester_repr, current_user=current_user)
@app.route("/")

View file

@ -2,7 +2,7 @@
{% extends "admin/master.html" %}
{% block body %}
{{information(current_user, active_semester, role="admin")}}
{{information(current_user, active_semester_repr, role="admin")}}
<hr>

View file

@ -2,6 +2,6 @@
{% extends "admin/model/create.html" %}
{% block body %}
{{information(current_user, active_semester, role="admin")}}
{{information(current_user, active_semester_repr, role="admin")}}
{{ super() }}
{% endblock %}

View file

@ -2,6 +2,6 @@
{% extends "admin/model/details.html" %}
{% block body %}
{{information(current_user, active_semester, role="admin")}}
{{information(current_user, active_semester_repr, role="admin")}}
{{ super() }}
{% endblock %}

View file

@ -2,6 +2,6 @@
{% extends "admin/model/edit.html" %}
{% block body %}
{{information(current_user, active_semester, role="admin")}}
{{information(current_user, active_semester_repr, role="admin")}}
{{ super() }}
{% endblock %}

View file

@ -2,7 +2,7 @@
{% extends "admin/index.html" %}
{% block body %}
{{information(current_user, active_semester, role="admin")}}
{{information(current_user, active_semester_repr, role="admin")}}
<hr>

View file

@ -2,6 +2,6 @@
{% extends "admin/model/list.html" %}
{% block body %}
{{information(current_user, active_semester, role="admin")}}
{{information(current_user, active_semester_repr, role="admin")}}
{{ super() }}
{% endblock %}

View file

@ -2,7 +2,7 @@
{% extends "admin/master.html" %}
{% block body %}
{{information(current_user, active_semester, role="admin")}}
{{information(current_user, active_semester_repr, role="admin")}}
<hr>

View file

@ -2,7 +2,7 @@
{% extends "admin/master.html" %}
{% block body %}
{{information(current_user, active_semester, role="admin")}}
{{information(current_user, active_semester_repr, role="admin")}}
<hr>

View file

@ -2,7 +2,7 @@
{% extends "admin/master.html" %}
{% block body %}
{{information(current_user, active_semester, role="admin")}}
{{information(current_user, active_semester_repr, role="admin")}}
<hr>

View file

@ -2,6 +2,6 @@
{% extends "admin/model/create.html" %}
{% block body %}
{{information(current_user, active_semester, role="assistant")}}
{{information(current_user, active_semester_repr, role="assistant")}}
{{ super() }}
{% endblock %}

View file

@ -2,6 +2,6 @@
{% extends "admin/model/details.html" %}
{% block body %}
{{information(current_user, active_semester, role="assistant")}}
{{information(current_user, active_semester_repr, role="assistant")}}
{{ super() }}
{% endblock %}

View file

@ -2,6 +2,6 @@
{% extends "admin/model/edit.html" %}
{% block body %}
{{information(current_user, active_semester, role="assistant")}}
{{information(current_user, active_semester_repr, role="assistant")}}
{{ super() }}
{% endblock %}

View file

@ -2,7 +2,7 @@
{% extends "admin/index.html" %}
{% block body %}
{{information(current_user, active_semester, role="assistant")}}
{{information(current_user, active_semester_repr, role="assistant")}}
<hr>

View file

@ -2,6 +2,6 @@
{% extends "admin/model/list.html" %}
{% block body %}
{{information(current_user, active_semester, role="assistant")}}
{{information(current_user, active_semester_repr, role="assistant")}}
{{ super() }}
{% endblock %}

View file

@ -2,7 +2,7 @@
{% extends "admin/master.html" %}
{% block body %}
{{information(current_user, active_semester, role="admin")}}
{{information(current_user, active_semester_repr, role="admin")}}
<hr>

View file

@ -1,7 +1,7 @@
{% macro information(current_user, active_semester, role) %}
{% macro information(current_user, active_semester_repr, role) %}
User: <a href="{{ url_for('index') }}{{ role }}/user/details/?id={{ current_user.id }}">{{ current_user.repr() }}</a>
| Active semester: {{ active_semester.repr() }}
| Active semester: {{ active_semester_repr() }}
{% if (role == "admin") and (current_user.has_role("assistant")) %}
| <a href="{{ url_for('index') }}assistant">Assistant space</a>.