diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a976fd..9834b4e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ ## Unreleased +* Display total hours played on homepage * Add format_duration to common.util.time * Allow deleting sessions * Redirect after adding game/platform/purchase/session diff --git a/src/web/tracker/templates/index.html b/src/web/tracker/templates/index.html index 831eb9b..16b8a27 100644 --- a/src/web/tracker/templates/index.html +++ b/src/web/tracker/templates/index.html @@ -5,7 +5,7 @@ {% block content %}
{% if session_count > 0 %} -You have played a total of {{ session_count }} sessions. +You have played a total of {{ session_count }} sessions for a total of {{ total_duration }}. {% else %} Start by clicking the links at the top. To track playtime, you need to have at least 1 owned game. {% endif %} diff --git a/src/web/tracker/views.py b/src/web/tracker/views.py index f100f16..12a1f7e 100644 --- a/src/web/tracker/views.py +++ b/src/web/tracker/views.py @@ -5,7 +5,8 @@ from .forms import SessionForm, PurchaseForm, GameForm, PlatformForm from datetime import datetime from zoneinfo import ZoneInfo from django.conf import settings -from common.util.time import now as now_with_tz +from common.util.time import now as now_with_tz, format_duration +from django.db.models import Sum def model_counts(request): @@ -102,4 +103,9 @@ def add_platform(request): def index(request): context = {} + result = Session.objects.all().aggregate(Sum("duration_calculated")) + context["total_duration"] = format_duration( + result["duration_calculated__sum"], "%H hours %m minutes" + ) + context["title"] = "Index" return render(request, "index.html", context)