Display total hours played on homepage
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Lukáš Kucharczyk 2023-01-05 11:24:07 +01:00
parent fdb9aa8e84
commit 32f10e183e
Signed by: lukas
SSH Key Fingerprint: SHA256:vMuSwvwAvcT6htVAioMP7rzzwMQNi3roESyhv+nAxeg
3 changed files with 9 additions and 2 deletions

View File

@ -1,4 +1,5 @@
## Unreleased ## Unreleased
* Display total hours played on homepage
* Add format_duration to common.util.time * Add format_duration to common.util.time
* Allow deleting sessions * Allow deleting sessions
* Redirect after adding game/platform/purchase/session * Redirect after adding game/platform/purchase/session

View File

@ -5,7 +5,7 @@
{% block content %} {% block content %}
<div class="text-slate-300 mx-auto max-w-screen-lg text-center"> <div class="text-slate-300 mx-auto max-w-screen-lg text-center">
{% if session_count > 0 %} {% 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 %} {% else %}
Start by clicking the links at the top. To track playtime, you need to have at least 1 owned game. Start by clicking the links at the top. To track playtime, you need to have at least 1 owned game.
{% endif %} {% endif %}

View File

@ -5,7 +5,8 @@ from .forms import SessionForm, PurchaseForm, GameForm, PlatformForm
from datetime import datetime from datetime import datetime
from zoneinfo import ZoneInfo from zoneinfo import ZoneInfo
from django.conf import settings 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): def model_counts(request):
@ -102,4 +103,9 @@ def add_platform(request):
def index(request): def index(request):
context = {} 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) return render(request, "index.html", context)