Add error handling if no Sessions exist
Django CI/CD / test (push) Successful in 1m12s Details
Django CI/CD / build-and-push (push) Successful in 2m30s Details

This commit is contained in:
Lukáš Kucharczyk 2024-11-27 18:35:44 +01:00
parent fc0d8db8e8
commit 13e607f9a7
Signed by: lukas
SSH Key Fingerprint: SHA256:vMuSwvwAvcT6htVAioMP7rzzwMQNi3roESyhv+nAxeg
1 changed files with 7 additions and 2 deletions

View File

@ -47,7 +47,10 @@ def list_sessions(request: HttpRequest, search_string: str = "") -> HttpResponse
| Q(device__name__icontains=search_string) | Q(device__name__icontains=search_string)
| Q(device__type__icontains=search_string) | Q(device__type__icontains=search_string)
) )
try:
last_session = sessions.latest() last_session = sessions.latest()
except Session.DoesNotExist:
last_session = None
page_obj = None page_obj = None
if int(limit) != 0: if int(limit) != 0:
paginator = Paginator(sessions, limit) paginator = Paginator(sessions, limit)
@ -109,7 +112,9 @@ def list_sessions(request: HttpRequest, search_string: str = "") -> HttpResponse
) )
], ],
), ),
), )
if last_session
else "",
] ]
), ),
], ],