diff --git a/highscores/templates/highscores/world_records.html b/highscores/templates/highscores/world_records.html new file mode 100644 index 0000000..225abb1 --- /dev/null +++ b/highscores/templates/highscores/world_records.html @@ -0,0 +1,33 @@ + + + + + World Records + + + +

World Records

+ + + + + + + + + + + + {% for record in world_records %} + + + + + + + + {% endfor %} + +
RankPlayerScoreGameTime Set
{{ forloop.counter }}{{ record.player.username }}{{ record.score }}{{ record.leaderboard.game }}{{ record.time_set }}
+ + diff --git a/highscores/urls.py b/highscores/urls.py index 6e1aa93..c7bea49 100644 --- a/highscores/urls.py +++ b/highscores/urls.py @@ -9,4 +9,5 @@ name="game leaderboard"), path("//", views.leaderboard_robot, name="robot leaderboard"), + path('world-records/', views.world_records, name='world-records'), ] diff --git a/highscores/views.py b/highscores/views.py index 4a26191..4c8a59e 100644 --- a/highscores/views.py +++ b/highscores/views.py @@ -14,6 +14,7 @@ SUBMIT_PAGE = "highscores/submit.html" SUBMIT_ACCEPTED_PAGE = "highscores/submit_accepted.html" SUBMIT_ERROR_PAGE = "highscores/submit_error.html" +WR_PAGE = "highscores/world_records.html" def home(request: HttpRequest) -> HttpResponse: @@ -50,6 +51,22 @@ def leaderboard_robot(request: HttpRequest, game_slug: str, name: str) -> HttpRe return render(request, "highscores/leaderboard_ranks.html", {"ls": context, "robot_name": name}) +def world_records(request: HttpRequest) -> HttpResponse: + # Get all leaderboards + leaderboards = Leaderboard.objects.all() + + # Collect the highest scores for each leaderboard + world_records = [] + for leaderboard in leaderboards: + highest_score = Score.objects.filter(leaderboard=leaderboard, approved=True).order_by('-score', 'time_set').first() + if highest_score: + world_records.append(highest_score) + + # Sort the world records by the date they were set + world_records.sort(key=lambda x: x.time_set) + + return render(request, WR_PAGE, {"world_records": world_records}) + def leaderboard_combined(request: HttpRequest, game_slug: str) -> HttpResponse: if not Leaderboard.objects.filter(game_slug=game_slug).exists():