2021-07-30 12:20:54 +00:00
|
|
|
from flask import flash, redirect, render_template, request, url_for
|
2022-02-13 18:58:05 +00:00
|
|
|
from flask_security import auth_required, current_user, roles_accepted, roles_required
|
2021-04-03 00:11:26 +00:00
|
|
|
|
2022-05-16 22:42:49 +00:00
|
|
|
from . import app, db
|
2022-05-16 23:28:50 +00:00
|
|
|
from .model_dependent_funs import (
|
|
|
|
active_semester_repr,
|
|
|
|
lastSemester,
|
|
|
|
setUserActiveSemester,
|
|
|
|
)
|
2022-05-16 22:42:49 +00:00
|
|
|
from .models import Semester
|
2021-03-18 13:53:55 +00:00
|
|
|
|
2021-03-31 23:04:21 +00:00
|
|
|
|
2021-03-20 14:41:22 +00:00
|
|
|
@app.context_processor
|
|
|
|
def util_processor():
|
2022-05-16 23:28:50 +00:00
|
|
|
return dict(active_semester_repr=active_semester_repr, current_user=current_user)
|
2021-03-20 14:41:22 +00:00
|
|
|
|
2021-03-31 23:04:21 +00:00
|
|
|
|
2021-03-18 13:53:55 +00:00
|
|
|
@app.route("/")
|
|
|
|
def index():
|
2021-05-17 20:15:50 +00:00
|
|
|
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:
|
2021-09-11 19:20:36 +00:00
|
|
|
return redirect(url_for("security.login"))
|
2021-03-18 22:20:59 +00:00
|
|
|
|
2021-05-17 20:36:24 +00:00
|
|
|
|
2021-06-09 00:51:26 +00:00
|
|
|
@app.route("/set_semester")
|
2021-04-17 00:19:38 +00:00
|
|
|
@auth_required()
|
|
|
|
def set_semester():
|
2021-07-11 11:48:13 +00:00
|
|
|
try:
|
|
|
|
semesterId = int(request.args.get("semester_id"))
|
|
|
|
except Exception as ex:
|
|
|
|
flash(str(ex), "error")
|
|
|
|
else:
|
2022-05-16 22:42:49 +00:00
|
|
|
semester = db.session.get(Semester, semesterId)
|
|
|
|
setUserActiveSemester(semester)
|
2021-07-11 11:48:13 +00:00
|
|
|
|
|
|
|
red = request.referrer or url_for("index")
|
2021-05-18 12:54:30 +00:00
|
|
|
return redirect(red)
|
2022-01-13 01:25:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
@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")
|