1
0
Fork 0
mirror of https://codeberg.org/Mo8it/AdvLabDB.git synced 2024-12-20 23:41:20 +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") @app.route("/students")
def students(): def students():
parts = Semester.query.first().parts parts = Semester.query.all()[-1].parts
tables = [] tables = []
tablesLabels = [] 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: for part in parts:
tablesLabels.append("Part" + part.label + ":") tablesLabels.append("Part " + part.label + ":")
tables.append(makeTable(headerAndDataList=headerAndDataList,
table = '<thead><tr>' rows=part.part_students))
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)
page = "students" page = "students"
return render_template(page + ".html", navbarItems=navbarItems(page), return render_template(page + ".html", navbarItems=navbarItems(page),
tables=tables, tablesLabels=tablesLabels) tables=tables, tablesLabels=tablesLabels)

View file

@ -31,7 +31,11 @@
</div> </div>
</div> </div>
</nav> </nav>
<div class="container-fluid">
<br>
{% block content %}{% endblock content %} {% block content %}{% endblock content %}
<br>
</div>
<!-- jQuery JS --> <!-- 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> <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,19 +2,21 @@
{% block content %} {% block content %}
{% for table in tables %} {% for table in tables %}
{{tablesLabels[loop.index0]}} <h2>{{tablesLabels[loop.index0]}}</h2>
<div class="table-responsive"> <table
<table data-classes="table table-bordered table-striped"
class="table table-striped" data-toggle="table"
data-toggle="table" data-thead-classes="table-dark"
data-search="true" data-search="true"
data-show-toggle="true" data-show-toggle="true"
data-show-columns="true" data-show-columns="true"
data-show-export="true" data-show-export="true"
data-export-types="['json', 'xml', 'csv', 'txt', 'sql', 'pdf']"> data-export-types="['json', 'xml', 'csv', 'txt', 'sql', 'pdf']">
{{table|safe}} {{table|safe}}
</table> </table>
</div> <br>
<hr>
<br>
{% else %} {% else %}
No parts in this semster yet! No parts in this semster yet!
{% endfor %} {% endfor %}

View file

@ -9,8 +9,26 @@ def navbarItems(activePage):
items += '<a class="nav-link' + active + '" href="' + lowerPage + '">' + page + '</a>' items += '<a class="nav-link' + active + '" href="' + lowerPage + '">' + page + '</a>'
return items return items
def td(cell): def makeTable(headerAndDataList, rows):
def td(cell):
return "<td>" + str(cell) + "</td>" return "<td>" + str(cell) + "</td>"
def th(cell): def th(cell):
return '<th data-sortable="true">' + str(cell) + '</th>' 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