Fix errors with empty database

This commit is contained in:
Lukáš Kucharczyk 2023-01-05 17:14:34 +01:00
parent 4e67735de8
commit 89be0c031b
Signed by: lukas
SSH Key Fingerprint: SHA256:vMuSwvwAvcT6htVAioMP7rzzwMQNi3roESyhv+nAxeg
2 changed files with 4 additions and 3 deletions

View File

@ -1,4 +1,5 @@
## Unreleased ## Unreleased
* Fix errors with empty database
* Fix negative playtimes being considered positive * Fix negative playtimes being considered positive
* Add %d for days to common.util.time.format_duration * Add %d for days to common.util.time.format_duration
* Set up tests, add tests for common.util.time * Set up tests, add tests for common.util.time

View File

@ -104,12 +104,12 @@ def add_platform(request):
def index(request): def index(request):
context = {} context = {}
if Session.objects.count() == 0: if Session.objects.count() == 0:
duration_value = 0 duration: str = ""
else: else:
result = Session.objects.all().aggregate(Sum("duration_calculated")) result = Session.objects.all().aggregate(Sum("duration_calculated"))
context["total_duration"] = format_duration( duration = format_duration(
result["duration_calculated__sum"], "%H hours %m minutes" result["duration_calculated__sum"], "%H hours %m minutes"
) )
context["total_duration"] = duration_value context["total_duration"] = duration
context["title"] = "Index" context["title"] = "Index"
return render(request, "index.html", context) return render(request, "index.html", context)