Expose page_count in pagination api. (#6982)

* Expose page_count in pagination api.

Fixes #6919

* Add docs
This commit is contained in:
Christopher Grebs 2017-11-22 15:03:09 +01:00 коммит произвёл GitHub
Родитель 5cda0d3aaf
Коммит b675677a7a
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 9 добавлений и 0 удалений

Просмотреть файл

@ -98,6 +98,7 @@ The following properties will be available in paginated responses:
* *next*: the URL for the next page in the pagination.
* *previous*: the URL for the previous page in the pagination.
* *page_size*: The number of items per page in the pagination.
* *page_count*: The number of pages available in the pagination.
* *count*: the total number of records.
* *results*: the array containing the results for this page.

Просмотреть файл

@ -17,6 +17,7 @@ class CustomPageNumberPagination(PageNumberPagination):
# Note that self.page_size doesn't work, it contains the default
# page size.
('page_size', self.page.paginator.per_page),
('page_count', self.page.paginator.num_pages),
('count', self.page.paginator.count),
('next', self.get_next_link()),
('previous', self.get_previous_link()),
@ -42,6 +43,7 @@ class OneOrZeroPageNumberPagination(CustomPageNumberPagination):
# return next/prev links.
return Response(OrderedDict([
('page_size', 1),
('page_count', 1),
('count', len(data)),
('next', None),
('previous', None),

Просмотреть файл

@ -31,6 +31,7 @@ class TestCustomPageNumberPagination(TestCase):
assert response.status_code == status.HTTP_200_OK
assert response.data == {
'page_size': 10,
'page_count': 10,
'results': range(11, 21),
'previous': 'http://testserver/?page_size=10',
'next': 'http://testserver/?page=3&page_size=10',
@ -43,6 +44,7 @@ class TestCustomPageNumberPagination(TestCase):
assert response.status_code == status.HTTP_200_OK
assert response.data == {
'page_size': 25,
'page_count': 4,
'results': range(1, 26),
'previous': None,
'next': 'http://testserver/?page=2',
@ -66,6 +68,7 @@ class TestESPageNumberPagination(TestCustomPageNumberPagination):
response = view(request)
assert response.data == {
'page_size': 5,
'page_count': 5000,
'results': mock.ANY,
'previous': 'http://testserver/?page=4998&page_size=5',
'next': 'http://testserver/?page=5000&page_size=5',
@ -76,6 +79,7 @@ class TestESPageNumberPagination(TestCustomPageNumberPagination):
response = view(request)
assert response.data == {
'page_size': 5,
'page_count': 5000,
'results': mock.ANY,
'previous': 'http://testserver/?page=4999&page_size=5',
'next': None,
@ -99,6 +103,7 @@ class TestOneOrZeroPageNumberPagination(TestCase):
response = self.view(request)
assert response.data == {
'page_size': 1,
'page_count': 1,
'results': range(1, 2),
'previous': None,
'next': None,
@ -115,6 +120,7 @@ class TestOneOrZeroPageNumberPagination(TestCase):
response = self.view(request)
assert response.data == {
'page_size': 1,
'page_count': 1,
'results': [],
'previous': None,
'next': None,