Start sessions of last purchase from list
continuous-integration/drone/push Build is passing Details

Fixes #19
This commit is contained in:
Lukáš Kucharczyk 2023-01-13 16:54:24 +01:00
parent d8ece979a8
commit 465d958d9b
6 changed files with 30 additions and 4 deletions

View File

@ -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

View File

@ -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 \

View File

@ -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

View File

@ -3,13 +3,18 @@
{% block title %}Sessions{% endblock title %}
{% block content %}
{% if purchase %}
<div class="text-center text-xl mb-4 dark:text-slate-400">
<a href="{% url 'start_session' dataset.last.purchase.id %}">
<button type="button" title="Track last tracked" class="py-1 px-2 bg-green-600 hover:bg-green-700 focus:ring-green-500 focus:ring-offset-blue-200 text-white transition ease-in duration-200 text-center text-base font-semibold shadow-md focus:outline-none focus:ring-2 focus:ring-offset-2 w-12 h-6 rounded-lg ">
New session of {{ dataset.last.purchase }}
</button>
</a>
{% if purchase %}
<h1>Listing sessions only for purchase "{{ purchase }}"</h1>
<h2>Total playtime: {{ total_duration }} over {{ dataset.count }} sessions.</h2>
<a class="dark:text-white hover:underline" href="{% url 'list_sessions' %}">View all sessions</a>
{% endif %}
</div>
{% endif %}
<div id="session-table" class="gap-4 shadow rounded-xl max-w-screen-lg mx-auto dark:bg-slate-700 p-2 justify-center">
<div class="dark:border-white dark:text-slate-300 text-lg">Name</div>
<div class="dark:border-white dark:text-slate-300 text-lg text-center">Start</div>

View File

@ -12,6 +12,11 @@ urlpatterns = [
views.update_session,
name="update_session",
),
path(
"start-session/<int:purchase_id>",
views.start_session,
name="start_session",
),
path(
"delete_session/by-id/<int:session_id>",
views.delete_session,

View File

@ -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()