mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-11-08 21:21:06 +00:00
Cleaned up routes.py
This commit is contained in:
parent
a6314e1c02
commit
b8da4fa8a8
2 changed files with 2 additions and 103 deletions
|
@ -1,7 +1,7 @@
|
||||||
from flask import flash, request, url_for
|
from flask import flash, request, url_for
|
||||||
from flask_admin.contrib.sqla.filters import BaseSQLAFilter
|
from flask_admin.contrib.sqla.filters import BaseSQLAFilter
|
||||||
from flask_admin.menu import MenuLink
|
from flask_admin.menu import MenuLink
|
||||||
from flask_security import hash_password, current_user
|
from flask_security import current_user, hash_password
|
||||||
from wtforms import BooleanField, SelectField, TextField
|
from wtforms import BooleanField, SelectField, TextField
|
||||||
from wtforms.validators import DataRequired, Email
|
from wtforms.validators import DataRequired, Email
|
||||||
|
|
||||||
|
|
|
@ -70,108 +70,7 @@ def index():
|
||||||
return render_template("index.html")
|
return render_template("index.html")
|
||||||
|
|
||||||
|
|
||||||
"""
|
@app.route("/set_semester")
|
||||||
@app.route("/assistants")
|
|
||||||
@roles_required("admin")
|
|
||||||
def assistants():
|
|
||||||
headerAndDataList = [["First name", "row.first_name"],
|
|
||||||
["Last name", "row.last_name"],
|
|
||||||
["Email", "row.email"],
|
|
||||||
["Phone number", "row.phone_number"],
|
|
||||||
["Mobile phone number", "row.mobile_phone_number"],
|
|
||||||
["Room", "row.room"],
|
|
||||||
["Building", "row.building"],
|
|
||||||
["User", "row.user"],
|
|
||||||
["Appointments", "row.appointments"],
|
|
||||||
["Experiment marks", "row.experiment_marks"]]
|
|
||||||
|
|
||||||
table = makeTable(headerAndDataList=headerAndDataList,
|
|
||||||
rows=Assistant.query.filter(Assistant.user_id != None).all())
|
|
||||||
|
|
||||||
return render_template("assistants.html",
|
|
||||||
table=table,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/experiments")
|
|
||||||
@roles_required("admin")
|
|
||||||
def experiments():
|
|
||||||
semester = Semester.query.get(current_user.active_semester_id)
|
|
||||||
parts = semester.parts
|
|
||||||
tables = []
|
|
||||||
tablesLabels = []
|
|
||||||
|
|
||||||
headerAndDataList = [["Number", "row.experiment.number"],
|
|
||||||
["Name", "row.experiment.name"],
|
|
||||||
["Assistants", "row.assistants"],
|
|
||||||
["Groups with this ex.", "[gEx.group.number for gEx in row.group_experiments]"]]
|
|
||||||
|
|
||||||
for part in parts:
|
|
||||||
tablesLabels.append("Part " + part.label + ":")
|
|
||||||
tables.append(makeTable(headerAndDataList=headerAndDataList,
|
|
||||||
rows=part.part_experiments))
|
|
||||||
|
|
||||||
return render_template("experiments.html",
|
|
||||||
tables=tables,
|
|
||||||
tablesLabels=tablesLabels,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/appointments")
|
|
||||||
@roles_required("admin")
|
|
||||||
def appointments():
|
|
||||||
return render_template("appointments.html",
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/groups")
|
|
||||||
@roles_required("admin")
|
|
||||||
def groups():
|
|
||||||
semester = Semester.query.get(current_user.active_semester_id)
|
|
||||||
parts = semester.parts
|
|
||||||
tables = []
|
|
||||||
tablesLabels = []
|
|
||||||
|
|
||||||
headerAndDataList = [["Number", "row.number"],
|
|
||||||
["Students",
|
|
||||||
"[ps.student.first_name + ' ' + ps.student.last_name for ps in row.part_students]"],
|
|
||||||
["Experiments (appointments)",
|
|
||||||
"[str(gx.part_experiment.experiment.number) + ' (' + str([appointmentDate(a.date) for a in gx.appointments]) + ')' for gx in row.group_experiments]"]]
|
|
||||||
|
|
||||||
for part in parts:
|
|
||||||
tablesLabels.append("Part " + part.label + ":")
|
|
||||||
tables.append(makeTable(headerAndDataList=headerAndDataList,
|
|
||||||
rows=part.groups))
|
|
||||||
|
|
||||||
return render_template("groups.html",
|
|
||||||
tables=tables,
|
|
||||||
tablesLabels=tablesLabels,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/deactivate_users", methods=["GET"])
|
|
||||||
@roles_required("admin")
|
|
||||||
def deactivate_users():
|
|
||||||
usersEmails = json.loads(request.args.get("json"))
|
|
||||||
deactivatedUsersEmails = []
|
|
||||||
for email in usersEmails:
|
|
||||||
user = User.query.filter(User.email == email).first()
|
|
||||||
if user == current_user:
|
|
||||||
flash("You have tried to deactivate yourself as user!", "danger")
|
|
||||||
continue
|
|
||||||
if user_datastore.deactivate_user(user):
|
|
||||||
deactivatedUsersEmails.append(email)
|
|
||||||
db.session.commit()
|
|
||||||
deactivatedUsersEmailsLen = len(deactivatedUsersEmails)
|
|
||||||
if deactivatedUsersEmailsLen == 0:
|
|
||||||
flash(f"No users deactivated!", "warning")
|
|
||||||
else:
|
|
||||||
flash(f"{deactivatedUsersEmailsLen} Users with emails {deactivatedUsersEmails} deactivated!", "success")
|
|
||||||
return redirect(url_for("users"))
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/set_semester", methods=["GET"])
|
|
||||||
@auth_required()
|
@auth_required()
|
||||||
def set_semester():
|
def set_semester():
|
||||||
setActiveSemester(request.args.get("semester_id"))
|
setActiveSemester(request.args.get("semester_id"))
|
||||||
|
|
Loading…
Reference in a new issue