from advlabdb import app from flask import render_template, request, url_for from advlabdb.utils import * from advlabdb.models import * activeSemester_id = Semester.query.all()[-1].id @app.context_processor def util_processor(): def semesterDropDownItems(): semesters = Semester.query.all() items = [] for semester in semesters: items.append('
  • ' + semester.label + '
  • ') return items return dict(semesterDropDownItems=semesterDropDownItems, activeSemesterLabel=Semester.query.get(activeSemester_id).label) @app.route("/") def index(): page = "index" return render_template(page + ".html", navbarItems=navbarItems(page)) @app.route("/students") def students(): semester = Semester.query.get(activeSemester_id) parts = semester.parts tables = [] tablesLabels = [] headerAndDataList = [["Student number", "row.student.student_number"], ["First name", "row.student.first_name"], ["Last name", "row.student.last_name"], ["Email", "row.student.email"], ["GN", "row.group.number"], ["Bachelor thesis", "row.student.bachelor_thesis"], ["BT WG", "row.student.bachelor_thesis_work_group"], ["Note", "row.student.note"], ["Final part mark", "row.final_part_mark"], ["Experiemt marks", "row.experiment_marks"], ["Parts", "[ps.part for ps in row.student.part_students]"]] for part in parts: tablesLabels.append("Part " + part.label + ":") tables.append(makeTable(headerAndDataList=headerAndDataList, rows=part.part_students)) page = "students" return render_template(page + ".html", navbarItems=navbarItems(page), tables=tables, tablesLabels=tablesLabels) @app.route("/assistants") 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"], ["Experiemt marks", "row.experiment_marks"]] table = makeTable(headerAndDataList=headerAndDataList, rows=Assistant.query.filter(Assistant.user_id != None).all()) page = "assistants" return render_template(page + ".html", navbarItems=navbarItems(page), table=table) @app.route("/experiments") def experiments(): semester = Semester.query.get(activeSemester_id) parts = semester.parts tables = [] tablesLabels = [] headerAndDataList = [["Name", "row.experiment.name"], ["Number", "row.number"], ["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)) page = "experiments" return render_template(page + ".html", navbarItems=navbarItems(page), tables=tables, tablesLabels=tablesLabels) @app.route("/appointments") def appointments(): page = "appointments" return render_template(page + ".html", navbarItems=navbarItems(page)) @app.route("/groups") def groups(): semester = Semester.query.get(activeSemester_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.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)) page = "groups" return render_template(page + ".html", navbarItems=navbarItems(page), tables=tables, tablesLabels=tablesLabels) @app.route("/users") def users(): headerAndDataList = [["Email", "row.email"], ["Is admin", "row.is_admin"], ["Assistant", "row.assistant"]] table = makeTable(headerAndDataList=headerAndDataList, rows=User.query.all()) page = "users" return render_template(page + ".html", navbarItems=navbarItems(page), table=table) @app.route("/set_semester", methods=["GET"]) def set_semester(): global activeSemester_id activeSemester_id = int(request.args.get("semester_id")) page = "index" return render_template(page + ".html", navbarItems=navbarItems(page)) @app.route("/semesters") def semesters(): headerAndDataList = [["Label", "row.label"], ["Parts", "row.parts"]] table = makeTable(headerAndDataList=headerAndDataList, rows=Semester.query.all()) page = "semesters" return render_template(page + ".html", navbarItems=navbarItems(page), table=table)