From 4b75a1dea97ef64d5c8d541c7b05670728fd91e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Mon, 15 Jan 2024 21:41:25 +0100 Subject: [PATCH] Increase session count on game overview when starting a new session --- CHANGELOG.md | 1 + games/templates/view_game.html | 14 ++++++++++++-- games/views.py | 11 +++++++++-- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8056f06..425068c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Improved * mark refunded purchases red on game overview +* increase session count on game overview when starting a new session ## Fixed * Fix title not being displayed on the Recent sessions page diff --git a/games/templates/view_game.html b/games/templates/view_game.html index 66053bc..4892dc1 100644 --- a/games/templates/view_game.html +++ b/games/templates/view_game.html @@ -57,13 +57,14 @@

Sessions - ({{ session_count }}) + ({{ session_count }}) {% url 'view_game_start_session_from_session' latest_session_id as add_session_link %} New @@ -85,18 +86,27 @@ hx-get="{{ end_session_url }}" hx-target="closest li" hx-swap="outerHTML" + hx-vals="js:{session_count:getSessionCount()}" hx-indicator="#indicator" > - + {% endif %}
  • {{ session.note|linebreaks }}
  • + {% endpartialdef %} {% endfor %} + {% endblock content %} diff --git a/games/views.py b/games/views.py index 57babe8..6ee53b8 100644 --- a/games/views.py +++ b/games/views.py @@ -1,5 +1,6 @@ from datetime import datetime from typing import Any, Callable +import re from django.db.models import ( Avg, @@ -247,7 +248,10 @@ def clone_session_by_id(session_id: int) -> Session: def new_session_from_existing_session(request, session_id: int, template: str = ""): session = clone_session_by_id(session_id) if request.htmx: - context = {"session": session} + context = { + "session": session, + "session_count": int(request.GET.get("session_count", 0)) + 1, + } return render(request, template, context) return redirect("list_sessions") @@ -258,7 +262,10 @@ def end_session(request, session_id: int, template: str = ""): session.timestamp_end = timezone.now() session.save() if request.htmx: - context = {"session": session} + context = { + "session": session, + "session_count": request.GET.get("session_count", 0), + } return render(request, template, context) return redirect("list_sessions")