Require search results be HTMX

This commit is contained in:
Jake Howard 2022-08-02 21:22:35 +01:00
parent 34293553a8
commit 809cc5d454
Signed by: jake
GPG key ID: 57AFB45680EDD477

View file

@ -1,6 +1,6 @@
from django.core.paginator import EmptyPage, Paginator from django.core.paginator import EmptyPage, Paginator
from django.http.request import HttpRequest from django.http.request import HttpRequest
from django.http.response import HttpResponse from django.http.response import HttpResponse, HttpResponseBadRequest
from django.shortcuts import render from django.shortcuts import render
from django.utils.decorators import method_decorator from django.utils.decorators import method_decorator
from django.utils.functional import cached_property from django.utils.functional import cached_property
@ -51,6 +51,9 @@ class SearchPage(BaseContentMixin, RoutablePageMixin, BasePage): # type: ignore
@route(r"^results/$") @route(r"^results/$")
@method_decorator(require_GET) @method_decorator(require_GET)
def results(self, request: HttpRequest) -> HttpResponse: def results(self, request: HttpRequest) -> HttpResponse:
if not request.htmx:
return HttpResponseBadRequest()
serializer = self.SearchParamsSerializer(data=request.GET) serializer = self.SearchParamsSerializer(data=request.GET)
if not serializer.is_valid(): if not serializer.is_valid():