-
Notifications
You must be signed in to change notification settings - Fork 33
/
actions.py
27 lines (23 loc) · 836 Bytes
/
actions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from django.http import HttpRequest
from django.http.response import HttpResponseRedirect
from django.shortcuts import get_object_or_404
from django.template.response import TemplateResponse
from htmx_patterns.models import Monster
from htmx_patterns.utils import for_htmx, is_htmx
@for_htmx(use_block_from_params=True)
def multiple_actions(request: HttpRequest, monster_id: int):
monster: Monster = get_object_or_404(Monster.objects.all(), id=monster_id)
if request.method == "POST":
if "kick" in request.POST:
monster.kick()
elif "hug" in request.POST:
monster.hug()
if not is_htmx(request):
return HttpResponseRedirect("")
return TemplateResponse(
request,
"multiple_actions.html",
{
"monster": monster,
},
)