Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
38e94bb8
Commit
38e94bb8
authored
Nov 15, 2012
by
Stephan Groß
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added global and per resource on/off switch + updated docs
parent
5967f15f
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
9 deletions
+22
-9
docs/api-guide/generic-views.md
+2
-1
docs/api-guide/settings.md
+6
-0
rest_framework/mixins.py
+11
-7
rest_framework/settings.py
+3
-1
No files found.
docs/api-guide/generic-views.md
View file @
38e94bb8
...
@@ -149,7 +149,8 @@ Should be mixed in with [MultipleObjectAPIView].
...
@@ -149,7 +149,8 @@ Should be mixed in with [MultipleObjectAPIView].
**Arguments**
:
**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
## CreateModelMixin
...
...
docs/api-guide/settings.md
View file @
38e94bb8
...
@@ -150,4 +150,10 @@ Default: `'accept'`
...
@@ -150,4 +150,10 @@ Default: `'accept'`
Default:
`'format'`
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/
[
cite
]:
http://www.python.org/dev/peps/pep-0020/
rest_framework/mixins.py
View file @
38e94bb8
...
@@ -7,6 +7,7 @@ which allows mixin classes to be composed in interesting ways.
...
@@ -7,6 +7,7 @@ which allows mixin classes to be composed in interesting ways.
from
django.http
import
Http404
from
django.http
import
Http404
from
rest_framework
import
status
from
rest_framework
import
status
from
rest_framework.response
import
Response
from
rest_framework.response
import
Response
from
rest_framework.settings
import
api_settings
class
CreateModelMixin
(
object
):
class
CreateModelMixin
(
object
):
...
@@ -32,6 +33,8 @@ class ListModelMixin(object):
...
@@ -32,6 +33,8 @@ class ListModelMixin(object):
Should be mixed in with `MultipleObjectAPIView`.
Should be mixed in with `MultipleObjectAPIView`.
"""
"""
empty_error
=
u"Empty list and '
%(class_name)
s.allow_empty' is False."
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
):
def
list
(
self
,
request
,
*
args
,
**
kwargs
):
self
.
object_list
=
self
.
get_filtered_queryset
()
self
.
object_list
=
self
.
get_filtered_queryset
()
...
@@ -56,13 +59,14 @@ class ListModelMixin(object):
...
@@ -56,13 +59,14 @@ class ListModelMixin(object):
return
Response
(
serializer
.
data
)
return
Response
(
serializer
.
data
)
def
get_paginate_by
(
self
,
queryset
):
def
get_paginate_by
(
self
,
queryset
):
page_size_param
=
self
.
request
.
QUERY_PARAMS
.
get
(
'page_size'
)
if
self
.
allow_page_size_param
:
if
page_size_param
:
page_size_param
=
self
.
request
.
QUERY_PARAMS
.
get
(
self
.
page_size_param
)
try
:
if
page_size_param
:
page_size
=
int
(
page_size_param
)
try
:
return
page_size
page_size
=
int
(
page_size_param
)
except
ValueError
:
return
page_size
pass
except
ValueError
:
pass
return
super
(
ListModelMixin
,
self
)
.
get_paginate_by
(
queryset
)
return
super
(
ListModelMixin
,
self
)
.
get_paginate_by
(
queryset
)
...
...
rest_framework/settings.py
View file @
38e94bb8
...
@@ -66,7 +66,9 @@ DEFAULTS = {
...
@@ -66,7 +66,9 @@ DEFAULTS = {
'URL_ACCEPT_OVERRIDE'
:
'accept'
,
'URL_ACCEPT_OVERRIDE'
:
'accept'
,
'URL_FORMAT_OVERRIDE'
:
'format'
,
'URL_FORMAT_OVERRIDE'
:
'format'
,
'FORMAT_SUFFIX_KWARG'
:
'format'
'FORMAT_SUFFIX_KWARG'
:
'format'
,
'ALLOW_PAGE_SIZE_PARAM'
:
True
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment