mirror of
https://github.com/iritmaximus/timetrials.git
synced 2026-10-12 19:13:48 +03:00
fix: from the courses view it is now possible to click on game and be
redirected to that games page.
This commit is contained in:
@@ -17,9 +17,9 @@ table, tr, td {
|
||||
</tr>
|
||||
{% for item in courses %}
|
||||
<tr>
|
||||
<td><a href="/courses/{{item[0]}}">{{item[0]}}</a></td>
|
||||
<td><a href="/games/{{item[1]}}">{{item[1]}}</a></td>
|
||||
<td><a href="/cups/{{item[2]}}">{{item[2]}}</a></td>
|
||||
<td><a href="/courses/{{item[0].replace(' ', '%20')}}">{{item[0]}}</a></td>
|
||||
<td><a href="/api/game/{{item[1].replace(' ', '%20')}}">{{item[1]}}</a></td>
|
||||
<td><a href="/cups/{{item[2].replace(' ', '%20')}}">{{item[2]}}</a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
@@ -7,6 +7,15 @@ def query_games():
|
||||
return result
|
||||
|
||||
|
||||
def query_game_by_name(game_name: str):
|
||||
sql = "SELECT id FROM games WHERE games.name=:game_name"
|
||||
result = db.session.execute(sql, {"game_name": game_name}).fetchone()
|
||||
if result:
|
||||
return result[0]
|
||||
else:
|
||||
raise ValueError(f"No game with name {game_name} found")
|
||||
|
||||
|
||||
def get_game_name(id: int):
|
||||
sql = f"SELECT name FROM games WHERE id=:id"
|
||||
result = db.session.execute(sql, {"id": id}).fetchone()
|
||||
|
||||
+17
-2
@@ -1,6 +1,11 @@
|
||||
from flask import render_template
|
||||
from flask import render_template, redirect
|
||||
from flaskr import app
|
||||
from flaskr.utils.games import query_games, get_game_name, get_all_times_in_game
|
||||
from flaskr.utils.games import (
|
||||
query_games,
|
||||
get_game_name,
|
||||
get_all_times_in_game,
|
||||
query_game_by_name,
|
||||
)
|
||||
|
||||
|
||||
@app.route("/games")
|
||||
@@ -22,3 +27,13 @@ def get_game_by_id(game_id):
|
||||
)
|
||||
times = get_all_times_in_game(game_id)
|
||||
return render_template("game_id.html", game_name=game_name, times=times)
|
||||
|
||||
|
||||
@app.route("/api/game/<string:game_name>")
|
||||
def get_game_by_name(game_name: str):
|
||||
try:
|
||||
game_name = str(game_name).replace("%20", " ")
|
||||
game_id = query_game_by_name(game_name)
|
||||
return redirect(f"/games/{game_id}")
|
||||
except ValueError as e:
|
||||
return render_template("error.html", message=f"Error fetching game name, {e}")
|
||||
|
||||
Reference in New Issue
Block a user