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

Fixed #3513 -- Fixed pagination for empty searches

This commit is contained in:
Morgan Aubert 2017-03-31 14:56:09 -04:00
parent 48949e69a7
commit 9be68178e4
4 changed files with 24 additions and 3 deletions

View File

@ -3,9 +3,12 @@ from __future__ import absolute_import, unicode_literals
from collections import OrderedDict
from django.conf import settings
from django.db.models.query import QuerySet
from rest_framework.pagination import BasePagination
from rest_framework.response import Response
from wagtail.wagtailsearch.backends.base import BaseSearchResults
from .utils import BadRequestError
@ -33,7 +36,8 @@ class WagtailPagination(BasePagination):
stop = offset + limit
self.view = view
self.total_count = queryset.count()
self.total_count = (queryset.count() if isinstance(queryset, QuerySet) or
isinstance(queryset, BaseSearchResults) else len(queryset))
return queryset[start:stop]
def get_paginated_response(self, data):

View File

@ -82,7 +82,6 @@ class TestPageListing(TestCase):
content = json.loads(response.content.decode('UTF-8'))
self.assertEqual(content['meta']['total_count'], new_total_count)
# TYPE FILTER
def test_type_filter_items_are_all_blog_entries(self):
@ -739,6 +738,13 @@ class TestPageListing(TestCase):
self.assertEqual(set(page_id_list), set([16, 18, 19]))
def test_empty_searches_work(self):
response = self.get_response(search='')
content = json.loads(response.content.decode('UTF-8'))
self.assertEqual(response.status_code, 200)
self.assertEqual(response['Content-type'], 'application/json')
self.assertEqual(content['meta']['total_count'], 0)
class TestPageDetail(TestCase):
fixtures = ['demosite.json']

View File

@ -3,9 +3,12 @@ from __future__ import absolute_import, unicode_literals
from collections import OrderedDict
from django.conf import settings
from django.db.models.query import QuerySet
from rest_framework.pagination import BasePagination
from rest_framework.response import Response
from wagtail.wagtailsearch.backends.base import BaseSearchResults
from .utils import BadRequestError
@ -33,7 +36,8 @@ class WagtailPagination(BasePagination):
stop = offset + limit
self.view = view
self.total_count = queryset.count()
self.total_count = (queryset.count() if isinstance(queryset, QuerySet) or
isinstance(queryset, BaseSearchResults) else len(queryset))
return queryset[start:stop]
def get_paginated_response(self, data):

View File

@ -534,6 +534,13 @@ class TestPageListing(TestCase):
self.assertEqual(response.status_code, 400)
self.assertEqual(content, {'message': "filtering by tag with a search query is not supported"})
def test_empty_searches_work(self):
response = self.get_response(search='')
content = json.loads(response.content.decode('UTF-8'))
self.assertEqual(response.status_code, 200)
self.assertEqual(response['Content-type'], 'application/json')
self.assertEqual(content['meta']['total_count'], 0)
class TestPageDetail(TestCase):
fixtures = ['demosite.json']