From a32d6c38ab169dc2f9b69800707360e1c1622fc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Thu, 16 Nov 2023 20:29:08 +0100 Subject: [PATCH] Account for no sessions --- games/templates/list_sessions.html | 4 ++++ games/views.py | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/games/templates/list_sessions.html b/games/templates/list_sessions.html index 90fa5ce..297c6ab 100644 --- a/games/templates/list_sessions.html +++ b/games/templates/list_sessions.html @@ -23,6 +23,7 @@ {% endif %} +{% if dataset.count != 0 %} @@ -73,4 +74,7 @@ {% endfor %}
+{% else %} +
No sessions found.
+{% endif %} {% endblock content %} diff --git a/games/views.py b/games/views.py index c6c1fe9..3054321 100644 --- a/games/views.py +++ b/games/views.py @@ -7,6 +7,7 @@ from django.http import HttpRequest, HttpResponse, HttpResponseRedirect from django.shortcuts import redirect, render from django.urls import reverse from django.utils import timezone +from django.core.exceptions import ObjectDoesNotExist from common.time import format_duration from common.utils import safe_division @@ -298,7 +299,10 @@ def list_sessions( context["total_duration"] = dataset.total_duration_formatted() context["dataset"] = dataset - context["last"] = Session.objects.latest() + try: + context["last"] = Session.objects.latest() + except ObjectDoesNotExist: + context["last"] = None return render(request, "list_sessions.html", context)