From e51d5862557bb3825e19e30df55e8073e636a4d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Mon, 16 Jan 2023 21:19:20 +0100 Subject: [PATCH] Automatically select purchase when adding session --- CHANGELOG.md | 5 +++++ src/web/tracker/models.py | 2 +- src/web/tracker/templates/list_sessions.html | 2 +- src/web/tracker/views.py | 4 +++- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d8d57c..9a0ccb1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## Unreleased + +* New + * When adding session, pre-select game with the last session + ## 0.2.4 / 2023-01-16 19:39+01:00 * Fixed diff --git a/src/web/tracker/models.py b/src/web/tracker/models.py index d1810bf..c393c35 100644 --- a/src/web/tracker/models.py +++ b/src/web/tracker/models.py @@ -81,7 +81,7 @@ class Session(models.Model): @property def last(self) -> Manager[Any]: - return Session.objects.all().order_by("timestamp_start")[:-1] + return Session.objects.all().order_by("timestamp_start")[0] def save(self, *args, **kwargs): if self.timestamp_start != None and self.timestamp_end != None: diff --git a/src/web/tracker/templates/list_sessions.html b/src/web/tracker/templates/list_sessions.html index 9c225ec..3bb6215 100644 --- a/src/web/tracker/templates/list_sessions.html +++ b/src/web/tracker/templates/list_sessions.html @@ -23,7 +23,7 @@ - {{ dataset.last.purchase }} + {{ last.purchase }} {% endif %} diff --git a/src/web/tracker/views.py b/src/web/tracker/views.py index ca4d85a..f12157c 100644 --- a/src/web/tracker/views.py +++ b/src/web/tracker/views.py @@ -22,7 +22,8 @@ def model_counts(request): def add_session(request): context = {} now = now_with_tz() - initial = {"timestamp_start": now} + last = Session.objects.all().last() + initial = {"timestamp_start": now, "purchase": last.purchase} form = SessionForm(request.POST or None, initial=initial) if form.is_valid(): form.save() @@ -74,6 +75,7 @@ def list_sessions(request, filter="", purchase_id="", platform_id="", game_id="" context["total_duration"] = dataset.total_duration() context["dataset"] = dataset + context["last"] = Session.objects.all().last() # charts are always oldest->newest context["chart"] = playtime_over_time_chart(dataset.order_by("timestamp_start"))