feat(game): add Submit & Create Session button to add-game form

Closes #31
This commit is contained in:
2026-06-20 19:49:00 +02:00
parent fe3e070669
commit e7a0eb7dca
2 changed files with 36 additions and 6 deletions
+19 -6
View File
@@ -163,6 +163,10 @@ def add_game(request: HttpRequest) -> HttpResponse:
return HttpResponseRedirect( return HttpResponseRedirect(
reverse("games:add_purchase_for_game", kwargs={"game_id": game.id}) reverse("games:add_purchase_for_game", kwargs={"game_id": game.id})
) )
elif "submit_and_create_session" in request.POST:
return HttpResponseRedirect(
reverse("games:add_session_for_game", kwargs={"game_id": game.id})
)
else: else:
return redirect("games:list_games") return redirect("games:list_games")
@@ -171,12 +175,21 @@ def add_game(request: HttpRequest) -> HttpResponse:
AddForm( AddForm(
form, form,
request=request, request=request,
additional_row=StyledButton( additional_row=Fragment(
[], StyledButton(
"Submit & Create Purchase", [],
color="gray", "Submit & Create Purchase",
type="submit", color="gray",
name="submit_and_redirect", type="submit",
name="submit_and_redirect",
),
StyledButton(
[],
"Submit & Create Session",
color="gray",
type="submit",
name="submit_and_create_session",
),
), ),
), ),
title="Add New Game", title="Add New Game",
+17
View File
@@ -128,12 +128,29 @@ class RenderedPagesTest(TestCase):
self.assertIn("dist/add_game.js", html) self.assertIn("dist/add_game.js", html)
self.assertIn("submit_and_redirect", html) self.assertIn("submit_and_redirect", html)
self.assertIn("Submit & Create Purchase", html) # & correctly escaped self.assertIn("Submit & Create Purchase", html) # & correctly escaped
self.assertIn("submit_and_create_session", html)
self.assertIn("Submit & Create Session", html) # & correctly escaped
# Fields self-style: label + control carry their own classes (no #add-form # Fields self-style: label + control carry their own classes (no #add-form
# / form CSS in input.css). # / form CSS in input.css).
self.assertIn("mb-2.5 text-sm font-medium text-heading", html) # _LABEL_CLASS self.assertIn("mb-2.5 text-sm font-medium text-heading", html) # _LABEL_CLASS
self.assertIn("bg-neutral-secondary-medium", html) # INPUT_CLASS surface self.assertIn("bg-neutral-secondary-medium", html) # INPUT_CLASS surface
self.assertNoEscapedTags(html) self.assertNoEscapedTags(html)
def test_add_game_submit_and_create_session_redirects(self):
response = self.client.post(
reverse("games:add_game"),
{
"name": "New Session Game",
"status": "u",
"submit_and_create_session": "",
},
)
game = Game.objects.get(name="New Session Game")
self.assertRedirects(
response,
reverse("games:add_session_for_game", kwargs={"game_id": game.id}),
)
def test_form_errors_render_with_component_class(self): def test_form_errors_render_with_component_class(self):
"""Invalid submits re-render field errors via FormFields' own class, not """Invalid submits re-render field errors via FormFields' own class, not
Django's .errorlist (which no longer exists in the CSS).""" Django's .errorlist (which no longer exists in the CSS)."""