mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-11-08 21:21:06 +00:00
48 lines
1.6 KiB
Python
48 lines
1.6 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 active_semester_str
|
|
from .models import Semester
|
|
|
|
|
|
@app.context_processor
|
|
def util_processor():
|
|
author_email = "mobitar@students.uni-mainz.de"
|
|
footer = f"<hr><p style='font-size:14px;'>This website is still under development (beta release)! If you have any questions, find any bugs or want some feature, please write a formless email (german/english) to Mo Bitar: <a href='mailto:{author_email}'>{author_email}</a>. Feedback is also welcome :)</p><br>"
|
|
return dict(active_semester_str=active_semester_str, current_user=current_user, footer=footer)
|
|
|
|
|
|
@app.route("/")
|
|
def index():
|
|
if current_user.has_role("admin"):
|
|
url = url_for("index") + "admin"
|
|
|
|
if current_user.login_count == 1:
|
|
url += "/docs"
|
|
|
|
return redirect(url)
|
|
elif current_user.has_role("assistant"):
|
|
url = url_for("index") + "assistant"
|
|
|
|
if current_user.login_count == 1:
|
|
url += "/docs"
|
|
|
|
return redirect(url)
|
|
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)
|
|
current_user.setActiveSemester(semester)
|
|
|
|
red = request.referrer or url_for("index")
|
|
return redirect(red)
|