0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-12-01 11:41:20 +01:00

Update pagination behaviour on search query chooser to match Django standard

This commit is contained in:
Matt Westcott 2023-06-09 21:02:37 +01:00
parent 1fe96e208d
commit b6b719709a
2 changed files with 12 additions and 6 deletions

View File

@ -176,10 +176,12 @@ class TestQueryChooserView(WagtailTestUtils, TestCase):
self.assertEqual(response.status_code, 200)
def test_pagination(self):
pages = ["0", "1", "-1", "9999", "Not a page"]
for page in pages:
response = self.get({"p": page})
self.assertEqual(response.status_code, 200)
# page numbers in range should be accepted
response = self.get({"p": 1})
self.assertEqual(response.status_code, 200)
# page numbers out of range should return 404
response = self.get({"p": 9999})
self.assertEqual(response.status_code, 404)
class TestSeparateFiltersFromQuery(SimpleTestCase):

View File

@ -1,4 +1,5 @@
from django.core.paginator import Paginator
from django.core.paginator import InvalidPage, Paginator
from django.http import Http404
from django.template.response import TemplateResponse
from wagtail.admin.forms.search import SearchForm
@ -23,7 +24,10 @@ def chooser(request, get_results=False):
searchform = SearchForm()
paginator = Paginator(queries, per_page=10)
queries = paginator.get_page(request.GET.get("p"))
try:
queries = paginator.page(request.GET.get("p", 1))
except InvalidPage:
raise Http404
# Render
if get_results: