Avoid errors when displaying game overview with zero sessions
Django CI/CD / test (push) Successful in 1m4s Details
Django CI/CD / build-and-push (push) Successful in 2m10s Details

This commit is contained in:
Lukáš Kucharczyk 2024-07-09 07:32:49 +02:00
parent 811fec4b11
commit 86f8fde8fa
Signed by: lukas
SSH Key Fingerprint: SHA256:vMuSwvwAvcT6htVAioMP7rzzwMQNi3roESyhv+nAxeg
3 changed files with 18 additions and 10 deletions

View File

@ -18,6 +18,7 @@
## Fixed
* Fix title not being displayed on the Recent sessions page
* Avoid errors when displaying game overview with zero sessions
## 1.5.2 / 2024-01-14 21:27+01:00

View File

@ -62,6 +62,7 @@
<h1 class="text-3xl mt-4 mb-1 flex gap-2 items-center">
Sessions
<span class="dark:text-slate-500" id="session-count">({{ session_count }})</span>
{% if latest_session_id %}
{% url 'view_game_start_session_from_session' latest_session_id as add_session_link %}
<a
class="truncate max-w-xs py-1 px-2 text-xs bg-green-600 hover:bg-green-700 focus:ring-green-500 focus:ring-offset-blue-200 text-white transition ease-in duration-200 text-center font-semibold shadow-md focus:outline-none focus:ring-2 focus:ring-offset-2 rounded-sm"
@ -72,6 +73,7 @@
hx-target="#session-list"
hx-swap="afterbegin"
>New</a>
{% endif %}
and Notes <span class="dark:text-slate-500">({{ sessions_with_notes_count }})</span>
</h1>
<ul id="session-list">

View File

@ -27,7 +27,7 @@ from django.utils import timezone
from django.shortcuts import get_object_or_404
from common.time import format_duration
from common.utils import safe_division
from common.utils import safe_division, safe_getattr
from .forms import (
DeviceForm,
@ -179,6 +179,7 @@ def view_game(request, game_id=None):
Session.objects.without_manual().filter(purchase__edition__game=game).count()
)
if sessions:
playrange_start = sessions.earliest().timestamp_start.strftime("%b %Y")
latest_session = sessions.latest()
playrange_end = latest_session.timestamp_start.strftime("%b %Y")
@ -188,6 +189,10 @@ def view_game(request, game_id=None):
if playrange_start == playrange_end
else f"{playrange_start}{playrange_end}"
)
else:
playrange = "N/A"
latest_session = None
total_hours = float(format_duration(sessions.total_duration_unformatted(), "%2.1H"))
total_hours_without_manual = float(
format_duration(sessions.calculated_duration_unformatted(), "%2.1H")
@ -209,7 +214,7 @@ def view_game(request, game_id=None):
"sessions": sessions.order_by("-timestamp_start"),
"title": f"Game Overview - {game.name}",
"hours_sum": total_hours,
"latest_session_id": latest_session.pk,
"latest_session_id": safe_getattr(latest_session, "pk"),
}
request.session["return_path"] = request.path