mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-11-08 21:21:06 +00:00
Added setting new semester as active semester
This commit is contained in:
parent
7e1a98b12b
commit
82ee852469
3 changed files with 24 additions and 6 deletions
|
@ -6,7 +6,7 @@ from wtforms import BooleanField, SelectField, TextField
|
||||||
from wtforms.validators import DataRequired, Email
|
from wtforms.validators import DataRequired, Email
|
||||||
|
|
||||||
from advlabdb import admin, app, user_datastore, db
|
from advlabdb import admin, app, user_datastore, db
|
||||||
from advlabdb.utils import randomPassword, userActiveSemester, partFromLabelInUserActiveSemester
|
from advlabdb.utils import randomPassword, userActiveSemester, partFromLabelInUserActiveSemester, setActiveSemester
|
||||||
from advlabdb.customClasses import SecureModelView
|
from advlabdb.customClasses import SecureModelView
|
||||||
from advlabdb.models import User, Role, Semester, Part, Student, PartStudent, Group, GroupExperiment, Experiment, Assistant, Appointment, PartExperiment, ExperimentMark
|
from advlabdb.models import User, Role, Semester, Part, Student, PartStudent, Group, GroupExperiment, Experiment, Assistant, Appointment, PartExperiment, ExperimentMark
|
||||||
|
|
||||||
|
@ -64,6 +64,12 @@ class SemesterModelView(SecureModelView):
|
||||||
db.session.add(Part(label=partLabel, semester=model))
|
db.session.add(Part(label=partLabel, semester=model))
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
|
if is_created:
|
||||||
|
admin.add_link(MenuLink(name=model.label,
|
||||||
|
url=url_for("set_semester") + "?semester_id=" + str(model.id),
|
||||||
|
category="Active semester"))
|
||||||
|
setActiveSemester(model.id)
|
||||||
|
|
||||||
|
|
||||||
class PartModelView(SecureModelView):
|
class PartModelView(SecureModelView):
|
||||||
can_view_details = True
|
can_view_details = True
|
||||||
|
|
|
@ -2,7 +2,7 @@ from advlabdb import app, db
|
||||||
from flask import render_template, request, url_for, flash, redirect
|
from flask import render_template, request, url_for, flash, redirect
|
||||||
from flask_security import auth_required, current_user
|
from flask_security import auth_required, current_user
|
||||||
|
|
||||||
from advlabdb.utils import titleToTemplate, userActiveSemester
|
from advlabdb.utils import titleToTemplate, userActiveSemester, setActiveSemester
|
||||||
from advlabdb.models import Semester
|
from advlabdb.models import Semester
|
||||||
|
|
||||||
|
|
||||||
|
@ -166,7 +166,7 @@ def deactivate_users():
|
||||||
@app.route("/set_semester", methods=["GET"])
|
@app.route("/set_semester", methods=["GET"])
|
||||||
@auth_required()
|
@auth_required()
|
||||||
def set_semester():
|
def set_semester():
|
||||||
current_user.active_semester_id = int(request.args.get("semester_id"))
|
setActiveSemester(request.args.get("semester_id"))
|
||||||
db.session.commit()
|
ref = request.referrer
|
||||||
flash("Active semester changed!", "warning")
|
red = ref if ref else url_for("index")
|
||||||
return redirect(request.referrer)
|
return redirect(red)
|
||||||
|
|
|
@ -95,3 +95,15 @@ def partFromLabelInUserActiveSemester(partLabel):
|
||||||
if part.label == partLabel:
|
if part.label == partLabel:
|
||||||
return part
|
return part
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def setActiveSemester(semesterId):
|
||||||
|
try:
|
||||||
|
current_user.active_semester_id = Semester.query.get(int(semesterId)).id
|
||||||
|
print(Semester.query.get(int(semesterId)))
|
||||||
|
except Exception as err:
|
||||||
|
flash(str(err))
|
||||||
|
return False
|
||||||
|
db.session.commit()
|
||||||
|
flash(f"Active semester changed to {Semester.query.get(semesterId).label}!", "warning")
|
||||||
|
return True
|
||||||
|
|
Loading…
Reference in a new issue