From 9c8ce39d04d9d4ca8becc5a2ef92ec0423fc1d84 Mon Sep 17 00:00:00 2001 From: iritmaximus Date: Sun, 5 Mar 2023 14:39:17 +0200 Subject: [PATCH] fix: count of cup_id --- flaskr/templates/cup_id.html | 13 +++++++------ flaskr/utils/cups.py | 7 ++++--- flaskr/views/cups.py | 9 +++++---- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/flaskr/templates/cup_id.html b/flaskr/templates/cup_id.html index a4f7b65..727b93e 100644 --- a/flaskr/templates/cup_id.html +++ b/flaskr/templates/cup_id.html @@ -8,22 +8,23 @@ table, tr, td { } +

There is {{count}} times in {{cup_name}}

Times

- - + + {% if times_exist %} {% for time in times %} - - - - + + + + {% endfor %} {% endif %} diff --git a/flaskr/utils/cups.py b/flaskr/utils/cups.py index 2f26245..a3be51c 100644 --- a/flaskr/utils/cups.py +++ b/flaskr/utils/cups.py @@ -38,7 +38,7 @@ def get_cup_id(course_id: int): raise ValueError("No cup found for current course") -def get_all_times_in_cup(id: int) -> list[str]: +def get_all_times_in_cup(id: int): """Queries the database for all times made in the wanted cup""" sql = """ @@ -49,6 +49,7 @@ def get_all_times_in_cup(id: int) -> list[str]: JOIN users ON times.user_id=users.id WHERE times.cup_id=:id """ - result = db.session.execute(sql, {"id": id}).fetchall() - return result + sql = "SELECT count(times.id) FROM times WHERE times.cup_id=:id" + count = db.session.execute(sql, {"id": id}).fetchone() + return result, count[0] diff --git a/flaskr/views/cups.py b/flaskr/views/cups.py index 034b236..529de4a 100644 --- a/flaskr/views/cups.py +++ b/flaskr/views/cups.py @@ -24,14 +24,15 @@ def get_cup_by_id(cup_id): cup_name = get_cup_name(cup_id) except ValueError as e: return render_template("error.html", message=f"Incorrect id, {e}") - times = get_all_times_in_cup(cup_id) - print(times) + times, count = get_all_times_in_cup(cup_id) if times: return render_template( - "cup_id.html", cup_name=cup_name, times=times, times_exist=True + "cup_id.html", cup_name=cup_name, times=times, times_exist=True, count=count ) else: - return render_template("cup_id.html", times_exist=False) + return render_template( + "cup_id.html", times_exist=False, count=count, cup_name=cup_name + ) @app.route("/api/cup/")
Time CourseCupGameTime User
{{time[0]}}{{time[1]}}{{time[2]}}{{time[3]}}{{time[0]}}{{time[1]}}{{time[2]}}{{time[3]}}