From 5bc04c463af6445607e525579d8cace9b48657df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Thu, 2 Nov 2023 09:20:09 +0100 Subject: [PATCH] Add stats link, year selector --- CHANGELOG.md | 4 ++++ games/static/base.css | 13 ++++++++----- games/templates/base.html | 1 + games/templates/stats.html | 10 +++++++++- games/urls.py | 1 + games/views.py | 9 ++++++++- 6 files changed, 31 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 68cb264..c27b267 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## Unreleased +### New +* Add Stats to the main navigation +* Allow selecting year on the Stats page + ### Fixed * Correctly limit sessions to a single year for stats diff --git a/games/static/base.css b/games/static/base.css index c755028..b8c5172 100644 --- a/games/static/base.css +++ b/games/static/base.css @@ -791,11 +791,6 @@ select { margin-bottom: 1rem; } -.my-5 { - margin-top: 1.25rem; - margin-bottom: 1.25rem; -} - .my-6 { margin-top: 1.5rem; margin-bottom: 1.5rem; @@ -805,6 +800,10 @@ select { margin-bottom: 0.25rem; } +.mb-10 { + margin-bottom: 2.5rem; +} + .mb-4 { margin-bottom: 1rem; } @@ -829,6 +828,10 @@ select { display: block; } +.inline-block { + display: inline-block; +} + .inline { display: inline; } diff --git a/games/templates/base.html b/games/templates/base.html index 20306e1..f06b17e 100644 --- a/games/templates/base.html +++ b/games/templates/base.html @@ -38,6 +38,7 @@
  • New Device
  • {% endif %} {% if session_count > 0 %} +
  • Stats
  • All Sessions
  • {% endif %} diff --git a/games/templates/stats.html b/games/templates/stats.html index 9ff2c12..a05c36f 100644 --- a/games/templates/stats.html +++ b/games/templates/stats.html @@ -6,7 +6,15 @@ {% block content %}
    -

    Stats for {{ year }}

    +
    +
    + + +
    +
    diff --git a/games/urls.py b/games/urls.py index 0bec6ce..fbc5849 100644 --- a/games/urls.py +++ b/games/urls.py @@ -73,6 +73,7 @@ urlpatterns = [ {"filter": "ownership_type"}, name="list_sessions_by_ownership_type", ), + path("stats/", views.stats, name="stats_current_year"), path( "stats/", views.stats, diff --git a/games/views.py b/games/views.py index 34076c0..a062dba 100644 --- a/games/views.py +++ b/games/views.py @@ -6,6 +6,8 @@ from common.time import format_duration from django.conf import settings from django.shortcuts import redirect, render from django.db.models import Sum, F +from django.http import HttpResponseRedirect +from django.urls import reverse from .forms import ( GameForm, @@ -230,7 +232,12 @@ def list_sessions( return render(request, "list_sessions.html", context) -def stats(request, year: int): +def stats(request, year: int = 0): + selected_year = request.GET.get("year") + if selected_year: + return HttpResponseRedirect(reverse("stats_by_year", args=[selected_year])) + if year == 0: + year = now_with_tz().year first_day_of_year = datetime(year, 1, 1) last_day_of_year = datetime(year + 1, 1, 1) year_sessions = Session.objects.filter(