mirror of
https://github.com/wagtail/wagtail.git
synced 2024-12-01 11:41:20 +01:00
Update pagination behaviour on page search to match Django standard
This commit is contained in:
parent
f0723eafd5
commit
62139a92b0
@ -71,11 +71,13 @@ class TestPageSearch(WagtailTestUtils, TransactionTestCase):
|
||||
self.assertEqual(response.context["query_string"], "Hello")
|
||||
|
||||
def test_pagination(self):
|
||||
pages = ["0", "1", "-1", "9999", "Not a page"]
|
||||
for page in pages:
|
||||
response = self.get({"q": "Hello", "p": page})
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertTemplateUsed(response, "wagtailadmin/pages/search.html")
|
||||
# page numbers in range should be accepted
|
||||
response = self.get({"q": "Hello", "p": 1})
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertTemplateUsed(response, "wagtailadmin/pages/search.html")
|
||||
# page numbers out of range should return 404
|
||||
response = self.get({"q": "Hello", "p": 9999})
|
||||
self.assertEqual(response.status_code, 404)
|
||||
|
||||
def test_root_can_appear_in_search_results(self):
|
||||
response = self.get({"q": "root"})
|
||||
|
@ -1,6 +1,6 @@
|
||||
from django.conf import settings
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
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 django.views.decorators.vary import vary_on_headers
|
||||
@ -113,7 +113,10 @@ def search(request):
|
||||
form = SearchForm()
|
||||
|
||||
paginator = Paginator(pages, per_page=20)
|
||||
pages = paginator.get_page(request.GET.get("p"))
|
||||
try:
|
||||
pages = paginator.page(request.GET.get("p", 1))
|
||||
except InvalidPage:
|
||||
raise Http404
|
||||
|
||||
if request.headers.get("x-requested-with") == "XMLHttpRequest":
|
||||
return TemplateResponse(
|
||||
|
Loading…
Reference in New Issue
Block a user