From 938c82a395a8bbe7fb047bdc682dc478c433b785 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Sun, 19 Feb 2023 14:30:26 +0100 Subject: [PATCH] Allow filtering by game, edition, purchase from the session list --- CHANGELOG.md | 4 ++++ common/input.css | 6 +++++- games/templates/list_sessions.html | 19 ++++++++++++++----- games/urls.py | 12 ++++++++++++ games/views.py | 16 +++++++++++++++- 5 files changed, 50 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4cfc751..5f134f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## Unreleased + +* Allow filtering by game, edition, purchase from the session list + ## 1.0.2 / 2023-02-18 21:48+01:00 * Add support for device info (https://git.kucharczyk.xyz/lukas/timetracker/issues/49) diff --git a/common/input.css b/common/input.css index 6d7bc5b..2ff5f48 100644 --- a/common/input.css +++ b/common/input.css @@ -14,7 +14,11 @@ textarea { #session-table { display: grid; - grid-template-columns: 3fr 1fr repeat(2, 2fr) 0.5fr 1fr; + grid-template-columns: 3fr repeat(3, 1fr) 0.5fr 1fr; +} + +.purchase-name:hover > span:nth-child(2) { + @apply dark:text-slate-300 } #button-container button { diff --git a/games/templates/list_sessions.html b/games/templates/list_sessions.html index 8f9f00b..e3d3a41 100644 --- a/games/templates/list_sessions.html +++ b/games/templates/list_sessions.html @@ -10,13 +10,13 @@ {% if dataset.count >= 1 %}
Total playtime: {{ total_duration }} over {{ dataset.count }} sessions.
{% endif %} - {% if purchase or platform or edition %} + {% if purchase or platform or edition or game or ownership_type %} - Filtering by "{% firstof purchase platform edition %}" + Filtering by "{% firstof purchase platform game edition ownership_type %}" {% if purchase %}See all platforms{% endif %} {% endif %} @@ -31,15 +31,24 @@ {% endif %} -
-
Name
+
+
Purchase
Platform
Start
End
Duration
Manage
{% for data in dataset %} - +
+ {{ data.purchase.edition }} ({{ data.purchase.get_ownership_type_display }}) + + + (G, + E, + P, + O) + +
{{ data.timestamp_start | date:"d/m/Y H:i" }}
diff --git a/games/urls.py b/games/urls.py index 0e276af..fbf626c 100644 --- a/games/urls.py +++ b/games/urls.py @@ -47,10 +47,22 @@ urlpatterns = [ {"filter": "platform"}, name="list_sessions_by_platform", ), + path( + "list-sessions/by-game/", + views.list_sessions, + {"filter": "game"}, + name="list_sessions_by_game", + ), path( "list-sessions/by-edition/", views.list_sessions, {"filter": "edition"}, name="list_sessions_by_edition", ), + path( + "list-sessions/by-ownership/", + views.list_sessions, + {"filter": "ownership_type"}, + name="list_sessions_by_ownership_type", + ), ] diff --git a/games/views.py b/games/views.py index 990e9ea..6fbcc76 100644 --- a/games/views.py +++ b/games/views.py @@ -110,7 +110,15 @@ def delete_session(request, session_id=None): return redirect("list_sessions") -def list_sessions(request, filter="", purchase_id="", platform_id="", edition_id=""): +def list_sessions( + request, + filter="", + purchase_id="", + platform_id="", + game_id="", + edition_id="", + ownership_type: str = "", +): context = {} context["title"] = "Sessions" @@ -123,6 +131,12 @@ def list_sessions(request, filter="", purchase_id="", platform_id="", edition_id elif filter == "edition": dataset = Session.objects.filter(purchase__edition=edition_id) context["edition"] = Edition.objects.get(id=edition_id) + elif filter == "game": + dataset = Session.objects.filter(purchase__edition__game=game_id) + context["game"] = Game.objects.get(id=game_id) + elif filter == "ownership_type": + dataset = Session.objects.filter(purchase__ownership_type=ownership_type) + context["ownership_type"] = dict(Purchase.OWNERSHIP_TYPES)[ownership_type] elif filter == "recent": dataset = Session.objects.filter( timestamp_start__gte=datetime.now() - timedelta(days=30)