1
0
Fork 0
mirror of https://codeberg.org/Mo8it/AdvLabDB.git synced 2024-11-08 21:21:06 +00:00

Added semesters page and dropdown

This commit is contained in:
Mo 2021-03-20 15:41:22 +01:00
parent 34145c8522
commit 4125b6cf8e
5 changed files with 73 additions and 15 deletions

View file

@ -3,6 +3,20 @@ 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('<li><a class="dropdown-item" href="' + url_for("set_semester") + "?semester_id=" +
str(semester.id) + '">' + semester.label + '</a></li>')
return items
return dict(semesterDropDownItems=semesterDropDownItems,
activeSemesterLabel=Semester.query.get(activeSemester_id).label)
@app.route("/")
def index():
page = "index"
@ -10,7 +24,7 @@ def index():
@app.route("/students")
def students():
semester = Semester.query.all()[-1]
semester = Semester.query.get(activeSemester_id)
parts = semester.parts
tables = []
tablesLabels = []
@ -57,7 +71,7 @@ def assistants():
@app.route("/experiments")
def experiments():
semester = Semester.query.all()[-1]
semester = Semester.query.get(activeSemester_id)
parts = semester.parts
tables = []
tablesLabels = []
@ -83,7 +97,7 @@ def appointments():
@app.route("/groups")
def groups():
semester = Semester.query.all()[-1]
semester = Semester.query.get(activeSemester_id)
parts = semester.parts
tables = []
tablesLabels = []
@ -115,3 +129,22 @@ def users():
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)

View file

@ -22,13 +22,27 @@
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="{{url_for('index')}}">AdvLabDB</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNavAltMarkup">
<div class="navbar-nav">
{{navbarItems|safe}}
</div>
<div class="collapse navbar-collapse" id="navbar">
<ul class="navbar-nav">
{% for item in navbarItems %}
<li class="nav-item">
{{item|safe}}
</li>
{% endfor %}
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" id="navbarDropdownMenuLink" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Semester {{activeSemesterLabel}}
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
{% for item in semesterDropDownItems() %}
{{item|safe}}
{% endfor %}
</ul>
</li>
</ul>
</div>
</div>
</nav>

View file

@ -0,0 +1,6 @@
{% extends "layout.html" %}
{% block content %}
{{table|safe}}
{% endblock content %}

View file

@ -1,17 +1,20 @@
def navbarItems(activePage):
pages = ["Students", "Assistants", "Experiments", "Appointments", "Groups", "Users"]
items = ""
pages = ["Students", "Assistants", "Experiments", "Appointments", "Groups", "Users", "Semesters"]
items = []
for page in pages:
active = ""
lowerPage = page.lower().replace(" ", "_")
if lowerPage == activePage:
active = " active"
items += '<a class="nav-link' + active + '" href="' + lowerPage + '">' + page + '</a>'
items.append('<a class="nav-link' + active + '" href="' + lowerPage + '">' + page + '</a>')
return items
def makeTable(headerAndDataList, rows):
def cellString(cell):
cell = str(cell)
if cell == "[]":
return "<em>None</em>"
excludeChars = """<>"'[]"""
for c in excludeChars:
if c in cell:

View file

@ -13,12 +13,14 @@ db.session.add(student1)
db.session.add(student2)
db.session.add(student3)
sem = Semester(label="SS2021")
sem1 = Semester(label="WS2021")
sem2 = Semester(label="SS21")
db.session.add(sem)
db.session.add(sem1)
db.session.add(sem2)
parta1 = Part(label="A/1", semester=sem)
partb2 = Part(label="B/2", semester=sem)
parta1 = Part(label="A/1", semester=sem2)
partb2 = Part(label="B/2", semester=sem2)
db.session.add(parta1)
db.session.add(partb2)