From 0b7da3550c47e8c7231fbc2475d4a2393107cbce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Thu, 14 Sep 2023 18:49:16 +0200 Subject: [PATCH] Change recent session view to current year --- CHANGELOG.md | 1 + games/views.py | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 63432f6..8ce9127 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ * Improve form appearance * Add helper buttons next to datime fields +* Change recent session view to current year instead of last 30 days ## 1.0.3 / 2023-02-20 17:16+01:00 diff --git a/games/views.py b/games/views.py index 3fdd805..b5a22e7 100644 --- a/games/views.py +++ b/games/views.py @@ -162,10 +162,12 @@ def list_sessions( dataset = Session.objects.filter(purchase__ownership_type=ownership_type) context["ownership_type"] = dict(Purchase.OWNERSHIP_TYPES)[ownership_type] elif filter == "recent": + current_year = datetime.now().year + first_day_of_year = datetime(current_year, 1, 1) dataset = Session.objects.filter( - timestamp_start__gte=datetime.now() - timedelta(days=30) + timestamp_start__gte=first_day_of_year ).order_by("-timestamp_start") - context["title"] = "Last 30 days" + context["title"] = "This year" else: # by default, sort from newest to oldest dataset = Session.objects.all().order_by("-timestamp_start")