fix stat dropdown
Django CI/CD / test (push) Successful in 1m16s Details
Django CI/CD / build-and-push (push) Successful in 2m7s Details

This commit is contained in:
Lukáš Kucharczyk 2024-10-16 18:31:12 +02:00
parent 9992d9c9bd
commit f8d621e710
Signed by: lukas
SSH Key Fingerprint: SHA256:vMuSwvwAvcT6htVAioMP7rzzwMQNi3roESyhv+nAxeg
4 changed files with 14 additions and 2 deletions

View File

@ -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)

View File

@ -122,7 +122,7 @@
</div>
</li>
<li>
<a href="{% url 'stats_by_year' 0 %}"
<a href="{% url 'stats_by_year' global_current_year %}"
class="block py-2 px-3 text-gray-900 rounded hover:bg-gray-100 md:hover:bg-transparent md:border-0 md:hover:text-blue-700 md:p-0 dark:text-white md:dark:hover:text-blue-500 dark:hover:bg-gray-700 dark:hover:text-white md:dark:hover:bg-transparent">Stats</a>
</li>
<li>

View File

@ -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

View File

@ -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",