Fix date range on game overview
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Lukáš Kucharczyk 2023-10-01 21:51:32 +02:00
parent e3ee832d3f
commit d2a9630b04
2 changed files with 10 additions and 5 deletions

View File

@ -7,7 +7,7 @@
{% block content %} {% block content %}
<div class="dark:text-white max-w-sm sm:max-w-xl lg:max-w-3xl mx-auto"> <div class="dark:text-white max-w-sm sm:max-w-xl lg:max-w-3xl mx-auto">
<h1 class="text-4xl">{{ game.name }} (#{{ game.pk }})</h1> <h1 class="text-4xl">{{ game.name }} (#{{ game.pk }})</h1>
<h2 class="text-lg my-2 ml-2">{{ total_playtime }} ({{ first_session.timestamp_end | date:"M Y"}} — {{ first_session.timestamp_end | date:"M Y"}}) </h2> <h2 class="text-lg my-2 ml-2">{{ total_playtime }} ({{ first_session.timestamp_end | date:"M Y"}} — {{ last_session.timestamp_end | date:"M Y"}}) </h2>
<hr class="border-slate-500"> <hr class="border-slate-500">
<h1 class="text-3xl mt-4 mb-1">Editions</h1> <h1 class="text-3xl mt-4 mb-1">Editions</h1>
<ul> <ul>
@ -33,7 +33,7 @@
<h1 class="text-3xl mt-4 mb-1">Sessions</h1> <h1 class="text-3xl mt-4 mb-1">Sessions</h1>
<ul> <ul>
{% for session in sessions %} {% for session in sessions %}
<li class="sm:pl-2">{{ session.timestamp_end | date:"d/m/Y" }} ({{ session.device.get_type_display | default:"Unknown" }}, {{ session.duration_formatted }})</li> <li class="sm:pl-2">{{ session.timestamp_start | date:"d/m/Y" }} ({{ session.device.get_type_display | default:"Unknown" }}, {{ session.duration_formatted }})</li>
{% endfor %} {% endfor %}
</ul> </ul>

View File

@ -98,10 +98,15 @@ def view_game(request, game_id=None):
context["game"] = game context["game"] = game
context["editions"] = Edition.objects.filter(game_id=game_id) context["editions"] = Edition.objects.filter(game_id=game_id)
context["purchases"] = Purchase.objects.filter(edition__game_id=game_id) context["purchases"] = Purchase.objects.filter(edition__game_id=game_id)
context["sessions"] = Session.objects.filter(purchase__edition__game_id=game_id) context["sessions"] = Session.objects.filter(
purchase__edition__game_id=game_id
).order_by("-timestamp_start")
context["total_playtime"] = context["sessions"].total_duration() context["total_playtime"] = context["sessions"].total_duration()
context["last_session"] = context["sessions"].last # here first and last is flipped
context["first_session"] = context["sessions"].first # because sessions are ordered from newest to oldest
# so the most recent are on top
context["last_session"] = context["sessions"].first()
context["first_session"] = context["sessions"].last()
return render(request, "view_game.html", context) return render(request, "view_game.html", context)