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:
parent
2236edb8aa
commit
6c268c3bb5
18 changed files with 32 additions and 23 deletions
|
@ -67,3 +67,12 @@ def reportBadAttempt(message):
|
||||||
|
|
||||||
def get_count(table):
|
def get_count(table):
|
||||||
return db.session.scalar(select(func.count()).select_from(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
|
||||||
|
|
|
@ -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 flask_security import auth_required, current_user, roles_accepted, roles_required
|
||||||
|
|
||||||
from . import app, db
|
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
|
from .models import Semester
|
||||||
|
|
||||||
|
|
||||||
@app.context_processor
|
@app.context_processor
|
||||||
def util_processor():
|
def util_processor():
|
||||||
active_semester = current_user.active_semester
|
return dict(active_semester_repr=active_semester_repr, current_user=current_user)
|
||||||
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)
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
{% extends "admin/master.html" %}
|
{% extends "admin/master.html" %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
{{information(current_user, active_semester, role="admin")}}
|
{{information(current_user, active_semester_repr, role="admin")}}
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,6 @@
|
||||||
{% extends "admin/model/create.html" %}
|
{% extends "admin/model/create.html" %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
{{information(current_user, active_semester, role="admin")}}
|
{{information(current_user, active_semester_repr, role="admin")}}
|
||||||
{{ super() }}
|
{{ super() }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -2,6 +2,6 @@
|
||||||
{% extends "admin/model/details.html" %}
|
{% extends "admin/model/details.html" %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
{{information(current_user, active_semester, role="admin")}}
|
{{information(current_user, active_semester_repr, role="admin")}}
|
||||||
{{ super() }}
|
{{ super() }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -2,6 +2,6 @@
|
||||||
{% extends "admin/model/edit.html" %}
|
{% extends "admin/model/edit.html" %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
{{information(current_user, active_semester, role="admin")}}
|
{{information(current_user, active_semester_repr, role="admin")}}
|
||||||
{{ super() }}
|
{{ super() }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
{% extends "admin/index.html" %}
|
{% extends "admin/index.html" %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
{{information(current_user, active_semester, role="admin")}}
|
{{information(current_user, active_semester_repr, role="admin")}}
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,6 @@
|
||||||
{% extends "admin/model/list.html" %}
|
{% extends "admin/model/list.html" %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
{{information(current_user, active_semester, role="admin")}}
|
{{information(current_user, active_semester_repr, role="admin")}}
|
||||||
{{ super() }}
|
{{ super() }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
{% extends "admin/master.html" %}
|
{% extends "admin/master.html" %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
{{information(current_user, active_semester, role="admin")}}
|
{{information(current_user, active_semester_repr, role="admin")}}
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
{% extends "admin/master.html" %}
|
{% extends "admin/master.html" %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
{{information(current_user, active_semester, role="admin")}}
|
{{information(current_user, active_semester_repr, role="admin")}}
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
{% extends "admin/master.html" %}
|
{% extends "admin/master.html" %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
{{information(current_user, active_semester, role="admin")}}
|
{{information(current_user, active_semester_repr, role="admin")}}
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,6 @@
|
||||||
{% extends "admin/model/create.html" %}
|
{% extends "admin/model/create.html" %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
{{information(current_user, active_semester, role="assistant")}}
|
{{information(current_user, active_semester_repr, role="assistant")}}
|
||||||
{{ super() }}
|
{{ super() }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -2,6 +2,6 @@
|
||||||
{% extends "admin/model/details.html" %}
|
{% extends "admin/model/details.html" %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
{{information(current_user, active_semester, role="assistant")}}
|
{{information(current_user, active_semester_repr, role="assistant")}}
|
||||||
{{ super() }}
|
{{ super() }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -2,6 +2,6 @@
|
||||||
{% extends "admin/model/edit.html" %}
|
{% extends "admin/model/edit.html" %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
{{information(current_user, active_semester, role="assistant")}}
|
{{information(current_user, active_semester_repr, role="assistant")}}
|
||||||
{{ super() }}
|
{{ super() }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
{% extends "admin/index.html" %}
|
{% extends "admin/index.html" %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
{{information(current_user, active_semester, role="assistant")}}
|
{{information(current_user, active_semester_repr, role="assistant")}}
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,6 @@
|
||||||
{% extends "admin/model/list.html" %}
|
{% extends "admin/model/list.html" %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
{{information(current_user, active_semester, role="assistant")}}
|
{{information(current_user, active_semester_repr, role="assistant")}}
|
||||||
{{ super() }}
|
{{ super() }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
{% extends "admin/master.html" %}
|
{% extends "admin/master.html" %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
{{information(current_user, active_semester, role="admin")}}
|
{{information(current_user, active_semester_repr, role="admin")}}
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
|
|
|
@ -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>
|
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")) %}
|
{% if (role == "admin") and (current_user.has_role("assistant")) %}
|
||||||
| <a href="{{ url_for('index') }}assistant">Assistant space</a>.
|
| <a href="{{ url_for('index') }}assistant">Assistant space</a>.
|
||||||
|
|
Loading…
Reference in a new issue