mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-11-08 21:21:06 +00:00
52 lines
1.5 KiB
Python
52 lines
1.5 KiB
Python
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 .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)
|
|
|
|
|
|
@app.route("/")
|
|
def index():
|
|
if current_user.has_role("admin"):
|
|
return redirect(url_for("index") + "admin")
|
|
elif current_user.has_role("assistant"):
|
|
return redirect(url_for("index") + "assistant")
|
|
else:
|
|
return redirect(url_for("security.login"))
|
|
|
|
|
|
@app.route("/set_semester")
|
|
@auth_required()
|
|
def set_semester():
|
|
try:
|
|
semesterId = int(request.args.get("semester_id"))
|
|
except Exception as ex:
|
|
flash(str(ex), "error")
|
|
else:
|
|
semester = db.session.get(Semester, semesterId)
|
|
setUserActiveSemester(semester)
|
|
|
|
red = request.referrer or url_for("index")
|
|
return redirect(red)
|
|
|
|
|
|
@app.route("/admin/docs")
|
|
@roles_required("admin")
|
|
def admin_docs():
|
|
return render_template("docs/admin.html")
|
|
|
|
|
|
@app.route("/assistant/docs")
|
|
@roles_accepted("admin", "assistant")
|
|
def assistant_docs():
|
|
return render_template("docs/assistant.html")
|