diff --git a/CHANGELOG.md b/CHANGELOG.md index cc33071..c0d2d51 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ -## Unreleased +## 0.2.1 / 2023-01-13 16:53+01:00 * List number of sessions when filtering on session list +* Start sessions of last purchase from list (https://git.kucharczyk.xyz/lukas/timetracker/issues/19) ## 0.2.0 / 2023-01-09 22:42+01:00 diff --git a/Dockerfile b/Dockerfile index 01a4194..ef92893 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,7 @@ RUN npm install && \ FROM python:3.10.9-alpine -ENV VERSION_NUMBER 0.2.0-1-g2defdd4 +ENV VERSION_NUMBER 0.2.0-2-gd8ece97 ENV PROD 1 RUN apk add \ diff --git a/src/web/tracker/models.py b/src/web/tracker/models.py index 66095d7..01321e5 100644 --- a/src/web/tracker/models.py +++ b/src/web/tracker/models.py @@ -4,6 +4,8 @@ from django.conf import settings from zoneinfo import ZoneInfo from common.util.time import format_duration from django.db.models import Sum, F +from django.db.models import Manager +from typing import Any class Game(models.Model): @@ -57,6 +59,9 @@ class Session(models.Model): def finish_now(self): self.timestamp_end = datetime.now(ZoneInfo(settings.TIME_ZONE)) + def start_now(): + self.timestamp_start = datetime.now(ZoneInfo(settings.TIME_ZONE)) + def duration_seconds(self) -> timedelta: manual = timedelta(0) calculated = timedelta(0) @@ -74,6 +79,10 @@ class Session(models.Model): def duration_sum(self) -> str: return Session.objects.all().total_duration() + @property + def last(self) -> Manager[Any]: + return Session.objects.all().order_by("timestamp_start")[:-1] + def save(self, *args, **kwargs): if self.timestamp_start != None and self.timestamp_end != None: self.duration_calculated = self.timestamp_end - self.timestamp_start diff --git a/src/web/tracker/templates/list_sessions.html b/src/web/tracker/templates/list_sessions.html index a9b5dfd..74df365 100644 --- a/src/web/tracker/templates/list_sessions.html +++ b/src/web/tracker/templates/list_sessions.html @@ -3,13 +3,18 @@ {% block title %}Sessions{% endblock title %} {% block content %} - {% if purchase %}
+ + + + {% if purchase %}

Listing sessions only for purchase "{{ purchase }}"

Total playtime: {{ total_duration }} over {{ dataset.count }} sessions.

View all sessions + {% endif %}
- {% endif %}
Name
Start
diff --git a/src/web/tracker/urls.py b/src/web/tracker/urls.py index cb9c6e1..4aa0f72 100644 --- a/src/web/tracker/urls.py +++ b/src/web/tracker/urls.py @@ -12,6 +12,11 @@ urlpatterns = [ views.update_session, name="update_session", ), + path( + "start-session/", + views.start_session, + name="start_session", + ), path( "delete_session/by-id/", views.delete_session, diff --git a/src/web/tracker/views.py b/src/web/tracker/views.py index 0e3e08b..ea1ace7 100644 --- a/src/web/tracker/views.py +++ b/src/web/tracker/views.py @@ -40,6 +40,12 @@ def update_session(request, session_id=None): return redirect("list_sessions") +def start_session(request, purchase_id=None): + session = SessionForm({"purchase": purchase_id, "timestamp_start": now_with_tz()}) + session.save() + return redirect("list_sessions") + + def delete_session(request, session_id=None): session = Session.objects.get(id=session_id) session.delete()