1
0
Fork 0
mirror of https://codeberg.org/Mo8it/AdvLabDB.git synced 2024-09-19 18:31:16 +00:00

Added makeTable() and container

This commit is contained in:
Mo 2021-03-19 16:30:02 +01:00
parent 8b14dd30d4
commit 849318f249
5 changed files with 65 additions and 66 deletions

View file

@ -10,51 +10,26 @@ def index():
@app.route("/students")
def students():
parts = Semester.query.first().parts
parts = Semester.query.all()[-1].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"],
["Bachelor thesis", "row.student.bachelor_thesis"],
["BT WG", "row.student.bachelor_thesis_work_group"],
["Note", "row.student.note"],
["Parts", "[ps.part for ps in row.student.part_students]"],
["Final part mark", "row.final_part_mark"],
["GN", "row.group.number"],
["Experiemt marks", "row.experiment_marks"]]
for part in parts:
tablesLabels.append("Part " + part.label + ":")
table = '<thead><tr>'
table += th("Student number")
table += th("First name")
table += th("Last name")
table += th("Email")
table += th("Bachelor thesis")
table += th("BT WG")
table += th("Note")
table += th("Parts")
table += th("Final part mark")
table += th("GN")
table += th("Experiemt marks")
table += '</tr></thead>\n<tbody>\n'
for partStudent in part.part_students:
student = partStudent.student
table += '<tr>'
table += td(student.student_number)
table += td(student.first_name)
table += td(student.last_name)
table += td(student.email)
table += td(student.bachelor_thesis)
table += td(student.bachelor_thesis_work_group)
table += td(student.note)
table += td([ps.part for ps in student.part_students])
table += td(partStudent.final_part_mark)
table += td(partStudent.group.number)
table += td(partStudent.experiment_marks)
table += '</tr>\n'
table += '</tbody>'
tables.append(table)
tables.append(makeTable(headerAndDataList=headerAndDataList,
rows=part.part_students))
page = "students"
return render_template(page + ".html", navbarItems=navbarItems(page),
tables=tables, tablesLabels=tablesLabels)

View file

@ -31,7 +31,11 @@
</div>
</div>
</nav>
<div class="container-fluid">
<br>
{% block content %}{% endblock content %}
<br>
</div>
<!-- jQuery JS -->
<script src="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>

View file

@ -2,11 +2,11 @@
{% block content %}
{% for table in tables %}
{{tablesLabels[loop.index0]}}
<div class="table-responsive">
<h2>{{tablesLabels[loop.index0]}}</h2>
<table
class="table table-striped"
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"
@ -14,7 +14,9 @@
data-export-types="['json', 'xml', 'csv', 'txt', 'sql', 'pdf']">
{{table|safe}}
</table>
</div>
<br>
<hr>
<br>
{% else %}
No parts in this semster yet!
{% endfor %}

View file

@ -9,8 +9,26 @@ def navbarItems(activePage):
items += '<a class="nav-link' + active + '" href="' + lowerPage + '">' + page + '</a>'
return items
def makeTable(headerAndDataList, rows):
def td(cell):
return "<td>" + str(cell) + "</td>"
def th(cell):
return '<th data-sortable="true">' + str(cell) + '</th>'
table = '<thead><tr>'
for i in headerAndDataList:
table += th(i[0])
table += '</tr></thead>\n<tbody>\n'
for row in rows:
table += '<tr>'
for i in headerAndDataList:
table += td(eval(i[1]))
table += '</tr>\n'
table += '</tbody>'
return table