diff --git a/common/time.py b/common/time.py index 7cf768a..e3921b3 100644 --- a/common/time.py +++ b/common/time.py @@ -163,3 +163,7 @@ def streak_bruteforce(datelist: list[date]) -> dict[str, int | tuple[date, date] else: increment_streak() return {"days": highest_streak, "dates": highest_streak_daterange} + + +def available_stats_year_range(): + return range(datetime.now().year, 1999, -1) diff --git a/games/templates/navbar.html b/games/templates/navbar.html index 7b4b08f..ff7de14 100644 --- a/games/templates/navbar.html +++ b/games/templates/navbar.html @@ -122,7 +122,7 @@
  • - Stats
  • diff --git a/games/views/general.py b/games/views/general.py index 5de7bf2..cc46180 100644 --- a/games/views/general.py +++ b/games/views/general.py @@ -1,3 +1,4 @@ +from datetime import datetime from typing import Any, Callable from django.contrib.auth.decorators import login_required @@ -8,7 +9,7 @@ from django.http import HttpRequest, HttpResponse, HttpResponseRedirect from django.shortcuts import redirect, render from django.urls import reverse -from common.time import dateformat, format_duration +from common.time import available_stats_year_range, dateformat, format_duration from common.utils import safe_division from games.models import Edition, Game, Platform, Purchase, Session @@ -23,6 +24,10 @@ def model_counts(request: HttpRequest) -> dict[str, bool]: } +def global_current_year(request: HttpRequest) -> dict[str, int]: + return {"global_current_year": datetime.now().year} + + def use_custom_redirect( func: Callable[..., HttpResponse], ) -> Callable[..., HttpResponse]: @@ -247,6 +252,7 @@ def stats_alltime(request: HttpRequest) -> HttpResponse: "last_play_game": last_play_game, "last_play_date": last_play_date, "title": f"{year} Stats", + "stats_dropdown_year_range": available_stats_year_range(), } request.session["return_path"] = request.path @@ -493,6 +499,7 @@ def stats(request: HttpRequest, year: int = 0) -> HttpResponse: "last_play_date": last_play_date, "title": f"{year} Stats", "month_playtimes": month_playtimes, + "stats_dropdown_year_range": available_stats_year_range(), } request.session["return_path"] = request.path diff --git a/timetracker/settings.py b/timetracker/settings.py index cfb1461..27a47eb 100644 --- a/timetracker/settings.py +++ b/timetracker/settings.py @@ -84,6 +84,7 @@ TEMPLATES = [ "django.contrib.auth.context_processors.auth", "django.contrib.messages.context_processors.messages", "games.views.general.model_counts", + "games.views.general.global_current_year", ], "builtins": [ "template_partials.templatetags.partials",