mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-12-20 23:41:20 +00:00
Fixed changing active semester
This commit is contained in:
parent
e50ad68d97
commit
c9143410d4
3 changed files with 23 additions and 13 deletions
File diff suppressed because one or more lines are too long
|
@ -1,4 +1,4 @@
|
||||||
from flask import redirect, render_template, request, url_for
|
from flask import redirect, render_template, request, url_for, flash
|
||||||
from flask_security import auth_required, current_user
|
from flask_security import auth_required, current_user
|
||||||
|
|
||||||
from advlabdb import app
|
from advlabdb import app
|
||||||
|
@ -73,7 +73,12 @@ def index():
|
||||||
@app.route("/set_semester")
|
@app.route("/set_semester")
|
||||||
@auth_required()
|
@auth_required()
|
||||||
def set_semester():
|
def set_semester():
|
||||||
setUserActiveSemester(request.args.get("semester_id"))
|
try:
|
||||||
ref = request.referrer
|
semesterId = int(request.args.get("semester_id"))
|
||||||
red = ref if ref else url_for("index")
|
except Exception as ex:
|
||||||
|
flash(str(ex), "error")
|
||||||
|
else:
|
||||||
|
setUserActiveSemester(semesterId)
|
||||||
|
|
||||||
|
red = request.referrer or url_for("index")
|
||||||
return redirect(red)
|
return redirect(red)
|
||||||
|
|
|
@ -102,11 +102,16 @@ def partFromLabelInUserActiveSemester(partLabel):
|
||||||
|
|
||||||
|
|
||||||
def setUserActiveSemester(semesterId):
|
def setUserActiveSemester(semesterId):
|
||||||
|
if current_user.active_semester_id != semesterId:
|
||||||
|
if Semester.query.get(semesterId):
|
||||||
try:
|
try:
|
||||||
current_user.active_semester_id = Semester.query.get(int(semesterId)).id
|
current_user.active_semester_id = semesterId
|
||||||
except Exception as err:
|
|
||||||
flash(str(err))
|
|
||||||
return False
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
except Exception as ex:
|
||||||
|
flash(str(ex), "error")
|
||||||
|
|
||||||
|
db.session.rollback()
|
||||||
|
else:
|
||||||
flash(f"Active semester changed to {Semester.query.get(semesterId).label}!", "warning")
|
flash(f"Active semester changed to {Semester.query.get(semesterId).label}!", "warning")
|
||||||
return True
|
else:
|
||||||
|
flash(f"No semester with ID {semesterId}!", "error")
|
||||||
|
|
Loading…
Reference in a new issue