fix: count of cup_id

This commit is contained in:
iritmaximus
2023-03-05 14:39:17 +02:00
parent 45c84cc0d9
commit 9c8ce39d04
3 changed files with 16 additions and 13 deletions
+7 -6
View File
@@ -8,22 +8,23 @@ table, tr, td {
}
</style>
<p>There is {{count}} times in {{cup_name}}</p>
<h2>Times</h2>
<table>
<tr>
<td>Time</td>
<td>Course</td>
<td>Cup</td>
<td>Game</td>
<td>Time</td>
<td>User</td>
</tr>
{% if times_exist %}
{% for time in times %}
<tr>
<td>{{time[0]}}</td>
<td><a href="/api/course/{{item[1].replace(' ', '%20')}}">{{time[1]}}</a></td>
<td><a href="/api/cup/{{item[2].replace(' ', '%20')}}">{{time[2]}}</a></td>
<td><a href="/api/game/{{item[3].replace(' ', '%20')}}">{{time[3]}}</a></td>
<td><a href="/api/course/{{time[0].replace(' ', '%20')}}">{{time[0]}}</a></td>
<td><a href="/api/game/{{time[1].replace(' ', '%20')}}">{{time[1]}}</a></td>
<td>{{time[2]}}</td>
<td>{{time[3]}}</td>
</tr>
{% endfor %}
{% endif %}
+4 -3
View File
@@ -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]
+5 -4
View File
@@ -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/<string:cup_name>")