mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-10 19:56:59 +03:00
added global and per resource on/off switch + updated docs
This commit is contained in:
parent
5967f15f7f
commit
38e94bb8b4
|
@ -149,7 +149,8 @@ Should be mixed in with [MultipleObjectAPIView].
|
|||
|
||||
**Arguments**:
|
||||
|
||||
* `page_size` - Hook to adjust page_size per request.
|
||||
* `allow_page_size_param` - Allows you to overwrite the global settings `ALLOW_PAGE_SIZE_PARAM` for a specific view.
|
||||
* `page_size_param` - Allows you to customize the page_size parameter. Default is `page_size`.
|
||||
|
||||
## CreateModelMixin
|
||||
|
||||
|
|
|
@ -150,4 +150,10 @@ Default: `'accept'`
|
|||
|
||||
Default: `'format'`
|
||||
|
||||
## ALLOW_PAGE_SIZE_PARAM
|
||||
|
||||
Allows you to globally pass a page size parameter for an individual request.
|
||||
|
||||
Default: `'True'`
|
||||
|
||||
[cite]: http://www.python.org/dev/peps/pep-0020/
|
||||
|
|
|
@ -7,6 +7,7 @@ which allows mixin classes to be composed in interesting ways.
|
|||
from django.http import Http404
|
||||
from rest_framework import status
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.settings import api_settings
|
||||
|
||||
|
||||
class CreateModelMixin(object):
|
||||
|
@ -32,6 +33,8 @@ class ListModelMixin(object):
|
|||
Should be mixed in with `MultipleObjectAPIView`.
|
||||
"""
|
||||
empty_error = u"Empty list and '%(class_name)s.allow_empty' is False."
|
||||
allow_page_size_param = api_settings.ALLOW_PAGE_SIZE_PARAM
|
||||
page_size_param = 'page_size'
|
||||
|
||||
def list(self, request, *args, **kwargs):
|
||||
self.object_list = self.get_filtered_queryset()
|
||||
|
@ -56,13 +59,14 @@ class ListModelMixin(object):
|
|||
return Response(serializer.data)
|
||||
|
||||
def get_paginate_by(self, queryset):
|
||||
page_size_param = self.request.QUERY_PARAMS.get('page_size')
|
||||
if page_size_param:
|
||||
try:
|
||||
page_size = int(page_size_param)
|
||||
return page_size
|
||||
except ValueError:
|
||||
pass
|
||||
if self.allow_page_size_param:
|
||||
page_size_param = self.request.QUERY_PARAMS.get(self.page_size_param)
|
||||
if page_size_param:
|
||||
try:
|
||||
page_size = int(page_size_param)
|
||||
return page_size
|
||||
except ValueError:
|
||||
pass
|
||||
return super(ListModelMixin, self).get_paginate_by(queryset)
|
||||
|
||||
|
||||
|
|
|
@ -66,7 +66,9 @@ DEFAULTS = {
|
|||
'URL_ACCEPT_OVERRIDE': 'accept',
|
||||
'URL_FORMAT_OVERRIDE': 'format',
|
||||
|
||||
'FORMAT_SUFFIX_KWARG': 'format'
|
||||
'FORMAT_SUFFIX_KWARG': 'format',
|
||||
|
||||
'ALLOW_PAGE_SIZE_PARAM': True
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user