Avoid errors when displaying game overview with zero sessions
This commit is contained in:
parent
811fec4b11
commit
86f8fde8fa
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
## Fixed
|
## Fixed
|
||||||
* Fix title not being displayed on the Recent sessions page
|
* 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
|
## 1.5.2 / 2024-01-14 21:27+01:00
|
||||||
|
|
||||||
|
|
|
@ -62,6 +62,7 @@
|
||||||
<h1 class="text-3xl mt-4 mb-1 flex gap-2 items-center">
|
<h1 class="text-3xl mt-4 mb-1 flex gap-2 items-center">
|
||||||
Sessions
|
Sessions
|
||||||
<span class="dark:text-slate-500" id="session-count">({{ session_count }})</span>
|
<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 %}
|
{% url 'view_game_start_session_from_session' latest_session_id as add_session_link %}
|
||||||
<a
|
<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"
|
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-target="#session-list"
|
||||||
hx-swap="afterbegin"
|
hx-swap="afterbegin"
|
||||||
>New</a>
|
>New</a>
|
||||||
|
{% endif %}
|
||||||
and Notes <span class="dark:text-slate-500">({{ sessions_with_notes_count }})</span>
|
and Notes <span class="dark:text-slate-500">({{ sessions_with_notes_count }})</span>
|
||||||
</h1>
|
</h1>
|
||||||
<ul id="session-list">
|
<ul id="session-list">
|
||||||
|
|
|
@ -27,7 +27,7 @@ from django.utils import timezone
|
||||||
from django.shortcuts import get_object_or_404
|
from django.shortcuts import get_object_or_404
|
||||||
|
|
||||||
from common.time import format_duration
|
from common.time import format_duration
|
||||||
from common.utils import safe_division
|
from common.utils import safe_division, safe_getattr
|
||||||
|
|
||||||
from .forms import (
|
from .forms import (
|
||||||
DeviceForm,
|
DeviceForm,
|
||||||
|
@ -179,15 +179,20 @@ def view_game(request, game_id=None):
|
||||||
Session.objects.without_manual().filter(purchase__edition__game=game).count()
|
Session.objects.without_manual().filter(purchase__edition__game=game).count()
|
||||||
)
|
)
|
||||||
|
|
||||||
playrange_start = sessions.earliest().timestamp_start.strftime("%b %Y")
|
if sessions:
|
||||||
latest_session = sessions.latest()
|
playrange_start = sessions.earliest().timestamp_start.strftime("%b %Y")
|
||||||
playrange_end = latest_session.timestamp_start.strftime("%b %Y")
|
latest_session = sessions.latest()
|
||||||
|
playrange_end = latest_session.timestamp_start.strftime("%b %Y")
|
||||||
|
|
||||||
|
playrange = (
|
||||||
|
playrange_start
|
||||||
|
if playrange_start == playrange_end
|
||||||
|
else f"{playrange_start} — {playrange_end}"
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
playrange = "N/A"
|
||||||
|
latest_session = None
|
||||||
|
|
||||||
playrange = (
|
|
||||||
playrange_start
|
|
||||||
if playrange_start == playrange_end
|
|
||||||
else f"{playrange_start} — {playrange_end}"
|
|
||||||
)
|
|
||||||
total_hours = float(format_duration(sessions.total_duration_unformatted(), "%2.1H"))
|
total_hours = float(format_duration(sessions.total_duration_unformatted(), "%2.1H"))
|
||||||
total_hours_without_manual = float(
|
total_hours_without_manual = float(
|
||||||
format_duration(sessions.calculated_duration_unformatted(), "%2.1H")
|
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"),
|
"sessions": sessions.order_by("-timestamp_start"),
|
||||||
"title": f"Game Overview - {game.name}",
|
"title": f"Game Overview - {game.name}",
|
||||||
"hours_sum": total_hours,
|
"hours_sum": total_hours,
|
||||||
"latest_session_id": latest_session.pk,
|
"latest_session_id": safe_getattr(latest_session, "pk"),
|
||||||
}
|
}
|
||||||
|
|
||||||
request.session["return_path"] = request.path
|
request.session["return_path"] = request.path
|
||||||
|
|
Loading…
Reference in New Issue