From 89be0c031b12abb363d55cfa380fb9a44091b5dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Thu, 5 Jan 2023 17:14:34 +0100 Subject: [PATCH] Fix errors with empty database --- CHANGELOG.md | 1 + src/web/tracker/views.py | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c7101a3..c0ba624 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ ## Unreleased +* Fix errors with empty database * Fix negative playtimes being considered positive * Add %d for days to common.util.time.format_duration * Set up tests, add tests for common.util.time diff --git a/src/web/tracker/views.py b/src/web/tracker/views.py index 05a200c..c0219da 100644 --- a/src/web/tracker/views.py +++ b/src/web/tracker/views.py @@ -104,12 +104,12 @@ def add_platform(request): def index(request): context = {} if Session.objects.count() == 0: - duration_value = 0 + duration: str = "" else: result = Session.objects.all().aggregate(Sum("duration_calculated")) - context["total_duration"] = format_duration( + duration = format_duration( result["duration_calculated__sum"], "%H hours %m minutes" ) - context["total_duration"] = duration_value + context["total_duration"] = duration context["title"] = "Index" return render(request, "index.html", context)