Skip to content

Commit

Permalink
[UI, ADMIN] Display email ipv username (#4202)
Browse files Browse the repository at this point in the history
* Displays email and username
* Shows active classes in overview

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
Felienne and pre-commit-ci[bot] authored Apr 15, 2023
1 parent f382d02 commit 94d3618
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 5 additions & 1 deletion templates/admin/admin-classes.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
<h1>Classes overview</h1>
<button type="reset" class="green-btn" id="return_to_admin_page_button" onclick="window.open('/admin', '_self');">Return to admin page</button>
</div>
<h4 class="text-center">Total amount of shown classes: {{ classes|length }}</h4>
<h4 class="text-center">Total amount of shown classes: {{ classes|length }} <br>
Total amount of active classes this week: {{ active_classes|length }}
<div class="program w-full mx-auto border-solid border-2 border-orange-400 rounded p-4">
<table class="table-auto w-full text-sm">
<thead>
<tr class="font-bold">
<td id="classname_header">Class name</td>
<td id="teacher_header">Teacher</td>
<td id="email_header">Email</td>
<td id="created_header">Created</td>
<td id="students_header">Students</td>
<td id="runs_week_header">Runs this week</td>
Expand All @@ -22,11 +24,13 @@ <h4 class="text-center">Total amount of shown classes: {{ classes|length }}</h4>
<td id="overview_header">Class overview</td>
</tr>
</thead>

<tbody>
{% for class in classes %}
<tr>
<td class="classname_cell">{{class.name}}</td>
<td class="teacher_cell">{{class.teacher}}</td>
<td class="email_cell">{{class.email}}</td>
<td class="created_cell">{{class.created}}</td>
<td class="students_cell">{{class.students}}</td>
<td class="runs_week_cell">{{class.stats.week.runs}}</td>
Expand Down
9 changes: 8 additions & 1 deletion website/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ def get_admin_classes_page(self, user):
classes = [
{
"name": Class.get("name"),
# replace email by username for easier communication
"teacher": Class.get("teacher"),
"email": self.db.user_by_username(Class.get("teacher")).get("email"),
"created": utils.localized_date_format(Class.get("date")),
"students": len(Class.get("students")) if "students" in Class else 0,
"stats": statistics.get_general_class_stats(Class.get("students", [])),
Expand All @@ -140,9 +142,14 @@ def get_admin_classes_page(self, user):
for Class in self.db.all_classes()
]

active_classes = [x for x in classes if x.get("stats").get("week").get("runs") > 0]

classes = sorted(classes, key=lambda d: d.get("stats").get("week").get("runs"), reverse=True)

return render_template("admin/admin-classes.html", classes=classes, page_title=gettext("title_admin"))
return render_template("admin/admin-classes.html",
active_classes=active_classes,
classes=classes,
page_title=gettext("title_admin"))

@route("/adventures", methods=["GET"])
@requires_admin
Expand Down

0 comments on commit 94d3618

Please sign in to comment.