feat(game): add Submit & Create Session button to add-game form
Closes #31
This commit is contained in:
+14
-1
@@ -163,6 +163,10 @@ def add_game(request: HttpRequest) -> HttpResponse:
|
||||
return HttpResponseRedirect(
|
||||
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:
|
||||
return redirect("games:list_games")
|
||||
|
||||
@@ -171,13 +175,22 @@ def add_game(request: HttpRequest) -> HttpResponse:
|
||||
AddForm(
|
||||
form,
|
||||
request=request,
|
||||
additional_row=StyledButton(
|
||||
additional_row=Fragment(
|
||||
StyledButton(
|
||||
[],
|
||||
"Submit & Create Purchase",
|
||||
color="gray",
|
||||
type="submit",
|
||||
name="submit_and_redirect",
|
||||
),
|
||||
StyledButton(
|
||||
[],
|
||||
"Submit & Create Session",
|
||||
color="gray",
|
||||
type="submit",
|
||||
name="submit_and_create_session",
|
||||
),
|
||||
),
|
||||
),
|
||||
title="Add New Game",
|
||||
scripts=ModuleScript("dist/elements/search-select.js")
|
||||
|
||||
@@ -128,12 +128,29 @@ class RenderedPagesTest(TestCase):
|
||||
self.assertIn("dist/add_game.js", html)
|
||||
self.assertIn("submit_and_redirect", html)
|
||||
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
|
||||
# / form CSS in input.css).
|
||||
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.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):
|
||||
"""Invalid submits re-render field errors via FormFields' own class, not
|
||||
Django's .errorlist (which no longer exists in the CSS)."""
|
||||
|
||||
Reference in New Issue
Block a user