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

Added assistants table

This commit is contained in:
Mo 2021-03-19 18:09:07 +01:00
parent 849318f249
commit e95cb842fe
4 changed files with 46 additions and 22 deletions

View file

@ -10,7 +10,8 @@ def index():
@app.route("/students") @app.route("/students")
def students(): def students():
parts = Semester.query.all()[-1].parts semester = Semester.query.all()[-1]
parts = semester.parts
tables = [] tables = []
tablesLabels = [] tablesLabels = []
@ -36,8 +37,23 @@ def students():
@app.route("/assistants") @app.route("/assistants")
def 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" page = "assistants"
return render_template(page + ".html", navbarItems=navbarItems(page)) return render_template(page + ".html", navbarItems=navbarItems(page),
table=table)
@app.route("/experiments") @app.route("/experiments")
def experiments(): def experiments():

View file

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

View file

@ -3,20 +3,7 @@
{% for table in tables %} {% for table in tables %}
<h2>{{tablesLabels[loop.index0]}}</h2> <h2>{{tablesLabels[loop.index0]}}</h2>
<table {{table|safe}}
data-classes="table table-bordered table-striped"
data-toggle="table"
data-thead-classes="table-dark"
data-search="true"
data-show-toggle="true"
data-show-columns="true"
data-show-export="true"
data-export-types="['json', 'xml', 'csv', 'txt', 'sql', 'pdf']">
{{table|safe}}
</table>
<br>
<hr>
<br>
{% else %} {% else %}
No parts in this semster yet! No parts in this semster yet!
{% endfor %} {% endfor %}

View file

@ -10,17 +10,31 @@ def navbarItems(activePage):
return items return items
def makeTable(headerAndDataList, rows): def makeTable(headerAndDataList, rows):
def cellString(cell):
return str(cell).replace("<", " ").replace(">", " ")
def td(cell): def td(cell):
return "<td>" + str(cell) + "</td>" return "<td>" + cellString(cell) + "</td>"
def th(cell): def th(cell):
return '<th data-sortable="true">' + str(cell) + '</th>' return '<th data-sortable="true">' + cellString(cell) + '</th>'
table = '''<table
table = '<thead><tr>' data-classes="table table-bordered table-striped"
data-toggle="table"
data-thead-classes="table-dark"
data-search="true"
data-show-toggle="true"
data-show-columns="true"
data-show-export="true"
data-export-types="['json', 'xml', 'csv', 'txt', 'sql', 'pdf']">
<thead>
<tr>'''
for i in headerAndDataList: for i in headerAndDataList:
table += th(i[0]) table += th(i[0])
table += '</tr></thead>\n<tbody>\n' table += '''</tr>
</thead>
<tbody>\n'''
for row in rows: for row in rows:
table += '<tr>' table += '<tr>'
@ -30,5 +44,9 @@ def makeTable(headerAndDataList, rows):
table += '</tr>\n' table += '</tr>\n'
table += '</tbody>' table += '''</tbody>
</table>
<br>
<hr>
<br>'''
return table return table