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
f087dcf7
Commit
f087dcf7
authored
Jul 30, 2015
by
Tom Christie
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3200 from tomchristie/version-3.2
Version 3.2 deprecations.
parents
ad599100
1b3b01e0
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
26 additions
and
123 deletions
+26
-123
rest_framework/pagination.py
+6
-5
rest_framework/request.py
+0
-47
rest_framework/serializers.py
+0
-40
rest_framework/views.py
+0
-11
tests/test_renderers.py
+1
-1
tests/test_request.py
+14
-14
tests/test_views.py
+5
-5
No files found.
rest_framework/pagination.py
View file @
f087dcf7
...
@@ -195,7 +195,8 @@ class PageNumberPagination(BasePagination):
...
@@ -195,7 +195,8 @@ class PageNumberPagination(BasePagination):
"""
"""
Prior to version 3.1, pagination was handled in the view, and the
Prior to version 3.1, pagination was handled in the view, and the
attributes were set there. The attributes should now be set on
attributes were set there. The attributes should now be set on
the pagination class, but the old style is still pending deprecation.
the pagination class. The old style continues to work but is deprecated
and will be fully removed in version 3.3.
"""
"""
assert
not
(
assert
not
(
getattr
(
view
,
'pagination_serializer_class'
,
None
)
or
getattr
(
view
,
'pagination_serializer_class'
,
None
)
or
...
@@ -216,11 +217,11 @@ class PageNumberPagination(BasePagination):
...
@@ -216,11 +217,11 @@ class PageNumberPagination(BasePagination):
if
value
is
not
None
:
if
value
is
not
None
:
setattr
(
self
,
attr_name
,
value
)
setattr
(
self
,
attr_name
,
value
)
warnings
.
warn
(
warnings
.
warn
(
"The `
%
s` settings key is
pending deprecation
. "
"The `
%
s` settings key is
deprecated
. "
"Use the `
%
s` attribute on the pagination class instead."
%
(
"Use the `
%
s` attribute on the pagination class instead."
%
(
settings_key
,
attr_name
settings_key
,
attr_name
),
),
Pending
DeprecationWarning
,
DeprecationWarning
,
)
)
for
(
view_attr
,
attr_name
)
in
(
for
(
view_attr
,
attr_name
)
in
(
...
@@ -233,11 +234,11 @@ class PageNumberPagination(BasePagination):
...
@@ -233,11 +234,11 @@ class PageNumberPagination(BasePagination):
if
value
is
not
None
:
if
value
is
not
None
:
setattr
(
self
,
attr_name
,
value
)
setattr
(
self
,
attr_name
,
value
)
warnings
.
warn
(
warnings
.
warn
(
"The `
%
s` view attribute is
pending deprecation
. "
"The `
%
s` view attribute is
deprecated
. "
"Use the `
%
s` attribute on the pagination class instead."
%
(
"Use the `
%
s` attribute on the pagination class instead."
%
(
view_attr
,
attr_name
view_attr
,
attr_name
),
),
Pending
DeprecationWarning
,
DeprecationWarning
,
)
)
def
paginate_queryset
(
self
,
queryset
,
request
,
view
=
None
):
def
paginate_queryset
(
self
,
queryset
,
request
,
view
=
None
):
...
...
rest_framework/request.py
View file @
f087dcf7
...
@@ -11,7 +11,6 @@ The wrapped request then offers a richer API, in particular :
...
@@ -11,7 +11,6 @@ The wrapped request then offers a richer API, in particular :
from
__future__
import
unicode_literals
from
__future__
import
unicode_literals
import
sys
import
sys
import
warnings
from
django.conf
import
settings
from
django.conf
import
settings
from
django.http
import
QueryDict
from
django.http
import
QueryDict
...
@@ -205,58 +204,12 @@ class Request(object):
...
@@ -205,58 +204,12 @@ class Request(object):
return
self
.
_request
.
GET
return
self
.
_request
.
GET
@property
@property
def
QUERY_PARAMS
(
self
):
"""
Synonym for `.query_params`, for backwards compatibility.
"""
warnings
.
warn
(
"`request.QUERY_PARAMS` is deprecated. Use `request.query_params` instead."
,
DeprecationWarning
,
stacklevel
=
1
)
return
self
.
_request
.
GET
@property
def
data
(
self
):
def
data
(
self
):
if
not
_hasattr
(
self
,
'_full_data'
):
if
not
_hasattr
(
self
,
'_full_data'
):
self
.
_load_data_and_files
()
self
.
_load_data_and_files
()
return
self
.
_full_data
return
self
.
_full_data
@property
@property
def
DATA
(
self
):
"""
Parses the request body and returns the data.
Similar to usual behaviour of `request.POST`, except that it handles
arbitrary parsers, and also works on methods other than POST (eg PUT).
"""
warnings
.
warn
(
"`request.DATA` is deprecated. Use `request.data` instead."
,
DeprecationWarning
,
stacklevel
=
1
)
if
not
_hasattr
(
self
,
'_data'
):
self
.
_load_data_and_files
()
return
self
.
_data
@property
def
FILES
(
self
):
"""
Parses the request body and returns any files uploaded in the request.
Similar to usual behaviour of `request.FILES`, except that it handles
arbitrary parsers, and also works on methods other than POST (eg PUT).
"""
warnings
.
warn
(
"`request.FILES` is deprecated. Use `request.data` instead."
,
DeprecationWarning
,
stacklevel
=
1
)
if
not
_hasattr
(
self
,
'_files'
):
self
.
_load_data_and_files
()
return
self
.
_files
@property
def
user
(
self
):
def
user
(
self
):
"""
"""
Returns the user associated with the current request, as authenticated
Returns the user associated with the current request, as authenticated
...
...
rest_framework/serializers.py
View file @
f087dcf7
...
@@ -12,8 +12,6 @@ response content is handled by parsers and renderers.
...
@@ -12,8 +12,6 @@ response content is handled by parsers and renderers.
"""
"""
from
__future__
import
unicode_literals
from
__future__
import
unicode_literals
import
warnings
from
django.db
import
models
from
django.db
import
models
from
django.db.models.fields
import
Field
as
DjangoModelField
from
django.db.models.fields
import
Field
as
DjangoModelField
from
django.db.models.fields
import
FieldDoesNotExist
from
django.db.models.fields
import
FieldDoesNotExist
...
@@ -1181,44 +1179,6 @@ class ModelSerializer(Serializer):
...
@@ -1181,44 +1179,6 @@ class ModelSerializer(Serializer):
kwargs
[
'read_only'
]
=
True
kwargs
[
'read_only'
]
=
True
extra_kwargs
[
field_name
]
=
kwargs
extra_kwargs
[
field_name
]
=
kwargs
# These are all pending deprecation.
write_only_fields
=
getattr
(
self
.
Meta
,
'write_only_fields'
,
None
)
if
write_only_fields
is
not
None
:
warnings
.
warn
(
"The `Meta.write_only_fields` option is deprecated. "
"Use `Meta.extra_kwargs={<field_name>: {'write_only': True}}` instead."
,
DeprecationWarning
,
stacklevel
=
3
)
for
field_name
in
write_only_fields
:
kwargs
=
extra_kwargs
.
get
(
field_name
,
{})
kwargs
[
'write_only'
]
=
True
extra_kwargs
[
field_name
]
=
kwargs
view_name
=
getattr
(
self
.
Meta
,
'view_name'
,
None
)
if
view_name
is
not
None
:
warnings
.
warn
(
"The `Meta.view_name` option is deprecated. "
"Use `Meta.extra_kwargs={'url': {'view_name': ...}}` instead."
,
DeprecationWarning
,
stacklevel
=
3
)
kwargs
=
extra_kwargs
.
get
(
self
.
url_field_name
,
{})
kwargs
[
'view_name'
]
=
view_name
extra_kwargs
[
self
.
url_field_name
]
=
kwargs
lookup_field
=
getattr
(
self
.
Meta
,
'lookup_field'
,
None
)
if
lookup_field
is
not
None
:
warnings
.
warn
(
"The `Meta.lookup_field` option is deprecated. "
"Use `Meta.extra_kwargs={'url': {'lookup_field': ...}}` instead."
,
DeprecationWarning
,
stacklevel
=
3
)
kwargs
=
extra_kwargs
.
get
(
self
.
url_field_name
,
{})
kwargs
[
'lookup_field'
]
=
lookup_field
extra_kwargs
[
self
.
url_field_name
]
=
kwargs
return
extra_kwargs
return
extra_kwargs
def
get_uniqueness_extra_kwargs
(
self
,
field_names
,
declared_fields
,
extra_kwargs
):
def
get_uniqueness_extra_kwargs
(
self
,
field_names
,
declared_fields
,
extra_kwargs
):
...
...
rest_framework/views.py
View file @
f087dcf7
...
@@ -3,9 +3,6 @@ Provides an APIView class that is the base of all views in REST framework.
...
@@ -3,9 +3,6 @@ Provides an APIView class that is the base of all views in REST framework.
"""
"""
from
__future__
import
unicode_literals
from
__future__
import
unicode_literals
import
inspect
import
warnings
from
django.core.exceptions
import
PermissionDenied
from
django.core.exceptions
import
PermissionDenied
from
django.db
import
models
from
django.db
import
models
from
django.http
import
Http404
from
django.http
import
Http404
...
@@ -428,14 +425,6 @@ class APIView(View):
...
@@ -428,14 +425,6 @@ class APIView(View):
exception_handler
=
self
.
settings
.
EXCEPTION_HANDLER
exception_handler
=
self
.
settings
.
EXCEPTION_HANDLER
if
len
(
inspect
.
getargspec
(
exception_handler
)
.
args
)
==
1
:
warnings
.
warn
(
'The `exception_handler(exc)` call signature is deprecated. '
'Use `exception_handler(exc, context) instead.'
,
DeprecationWarning
)
response
=
exception_handler
(
exc
)
else
:
context
=
self
.
get_exception_handler_context
()
context
=
self
.
get_exception_handler_context
()
response
=
exception_handler
(
exc
,
context
)
response
=
exception_handler
(
exc
,
context
)
...
...
tests/test_renderers.py
View file @
f087dcf7
...
@@ -81,7 +81,7 @@ class MockGETView(APIView):
...
@@ -81,7 +81,7 @@ class MockGETView(APIView):
class
MockPOSTView
(
APIView
):
class
MockPOSTView
(
APIView
):
def
post
(
self
,
request
,
**
kwargs
):
def
post
(
self
,
request
,
**
kwargs
):
return
Response
({
'foo'
:
request
.
DATA
})
return
Response
({
'foo'
:
request
.
data
})
class
EmptyGETView
(
APIView
):
class
EmptyGETView
(
APIView
):
...
...
tests/test_request.py
View file @
f087dcf7
...
@@ -76,37 +76,37 @@ class TestMethodOverloading(TestCase):
...
@@ -76,37 +76,37 @@ class TestMethodOverloading(TestCase):
class
TestContentParsing
(
TestCase
):
class
TestContentParsing
(
TestCase
):
def
test_standard_behaviour_determines_no_content_GET
(
self
):
def
test_standard_behaviour_determines_no_content_GET
(
self
):
"""
"""
Ensure request.
DATA
returns empty QueryDict for GET request.
Ensure request.
data
returns empty QueryDict for GET request.
"""
"""
request
=
Request
(
factory
.
get
(
'/'
))
request
=
Request
(
factory
.
get
(
'/'
))
self
.
assertEqual
(
request
.
DATA
,
{})
self
.
assertEqual
(
request
.
data
,
{})
def
test_standard_behaviour_determines_no_content_HEAD
(
self
):
def
test_standard_behaviour_determines_no_content_HEAD
(
self
):
"""
"""
Ensure request.
DATA
returns empty QueryDict for HEAD request.
Ensure request.
data
returns empty QueryDict for HEAD request.
"""
"""
request
=
Request
(
factory
.
head
(
'/'
))
request
=
Request
(
factory
.
head
(
'/'
))
self
.
assertEqual
(
request
.
DATA
,
{})
self
.
assertEqual
(
request
.
data
,
{})
def
test_request_DATA_with_form_content
(
self
):
def
test_request_DATA_with_form_content
(
self
):
"""
"""
Ensure request.
DATA
returns content for POST request with form content.
Ensure request.
data
returns content for POST request with form content.
"""
"""
data
=
{
'qwerty'
:
'uiop'
}
data
=
{
'qwerty'
:
'uiop'
}
request
=
Request
(
factory
.
post
(
'/'
,
data
))
request
=
Request
(
factory
.
post
(
'/'
,
data
))
request
.
parsers
=
(
FormParser
(),
MultiPartParser
())
request
.
parsers
=
(
FormParser
(),
MultiPartParser
())
self
.
assertEqual
(
list
(
request
.
DATA
.
items
()),
list
(
data
.
items
()))
self
.
assertEqual
(
list
(
request
.
data
.
items
()),
list
(
data
.
items
()))
def
test_request_DATA_with_text_content
(
self
):
def
test_request_DATA_with_text_content
(
self
):
"""
"""
Ensure request.
DATA
returns content for POST request with
Ensure request.
data
returns content for POST request with
non-form content.
non-form content.
"""
"""
content
=
six
.
b
(
'qwerty'
)
content
=
six
.
b
(
'qwerty'
)
content_type
=
'text/plain'
content_type
=
'text/plain'
request
=
Request
(
factory
.
post
(
'/'
,
content
,
content_type
=
content_type
))
request
=
Request
(
factory
.
post
(
'/'
,
content
,
content_type
=
content_type
))
request
.
parsers
=
(
PlainTextParser
(),)
request
.
parsers
=
(
PlainTextParser
(),)
self
.
assertEqual
(
request
.
DATA
,
content
)
self
.
assertEqual
(
request
.
data
,
content
)
def
test_request_POST_with_form_content
(
self
):
def
test_request_POST_with_form_content
(
self
):
"""
"""
...
@@ -119,27 +119,27 @@ class TestContentParsing(TestCase):
...
@@ -119,27 +119,27 @@ class TestContentParsing(TestCase):
def
test_standard_behaviour_determines_form_content_PUT
(
self
):
def
test_standard_behaviour_determines_form_content_PUT
(
self
):
"""
"""
Ensure request.
DATA
returns content for PUT request with form content.
Ensure request.
data
returns content for PUT request with form content.
"""
"""
data
=
{
'qwerty'
:
'uiop'
}
data
=
{
'qwerty'
:
'uiop'
}
request
=
Request
(
factory
.
put
(
'/'
,
data
))
request
=
Request
(
factory
.
put
(
'/'
,
data
))
request
.
parsers
=
(
FormParser
(),
MultiPartParser
())
request
.
parsers
=
(
FormParser
(),
MultiPartParser
())
self
.
assertEqual
(
list
(
request
.
DATA
.
items
()),
list
(
data
.
items
()))
self
.
assertEqual
(
list
(
request
.
data
.
items
()),
list
(
data
.
items
()))
def
test_standard_behaviour_determines_non_form_content_PUT
(
self
):
def
test_standard_behaviour_determines_non_form_content_PUT
(
self
):
"""
"""
Ensure request.
DATA
returns content for PUT request with
Ensure request.
data
returns content for PUT request with
non-form content.
non-form content.
"""
"""
content
=
six
.
b
(
'qwerty'
)
content
=
six
.
b
(
'qwerty'
)
content_type
=
'text/plain'
content_type
=
'text/plain'
request
=
Request
(
factory
.
put
(
'/'
,
content
,
content_type
=
content_type
))
request
=
Request
(
factory
.
put
(
'/'
,
content
,
content_type
=
content_type
))
request
.
parsers
=
(
PlainTextParser
(),
)
request
.
parsers
=
(
PlainTextParser
(),
)
self
.
assertEqual
(
request
.
DATA
,
content
)
self
.
assertEqual
(
request
.
data
,
content
)
def
test_overloaded_behaviour_allows_content_tunnelling
(
self
):
def
test_overloaded_behaviour_allows_content_tunnelling
(
self
):
"""
"""
Ensure request.
DATA
returns content for overloaded POST request.
Ensure request.
data
returns content for overloaded POST request.
"""
"""
json_data
=
{
'foobar'
:
'qwerty'
}
json_data
=
{
'foobar'
:
'qwerty'
}
content
=
json
.
dumps
(
json_data
)
content
=
json
.
dumps
(
json_data
)
...
@@ -150,7 +150,7 @@ class TestContentParsing(TestCase):
...
@@ -150,7 +150,7 @@ class TestContentParsing(TestCase):
}
}
request
=
Request
(
factory
.
post
(
'/'
,
form_data
))
request
=
Request
(
factory
.
post
(
'/'
,
form_data
))
request
.
parsers
=
(
JSONParser
(),
)
request
.
parsers
=
(
JSONParser
(),
)
self
.
assertEqual
(
request
.
DATA
,
json_data
)
self
.
assertEqual
(
request
.
data
,
json_data
)
def
test_form_POST_unicode
(
self
):
def
test_form_POST_unicode
(
self
):
"""
"""
...
...
tests/test_views.py
View file @
f087dcf7
...
@@ -25,7 +25,7 @@ class BasicView(APIView):
...
@@ -25,7 +25,7 @@ class BasicView(APIView):
return
Response
({
'method'
:
'GET'
})
return
Response
({
'method'
:
'GET'
})
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
return
Response
({
'method'
:
'POST'
,
'data'
:
request
.
DATA
})
return
Response
({
'method'
:
'POST'
,
'data'
:
request
.
data
})
@api_view
([
'GET'
,
'POST'
,
'PUT'
,
'PATCH'
])
@api_view
([
'GET'
,
'POST'
,
'PUT'
,
'PATCH'
])
...
@@ -33,11 +33,11 @@ def basic_view(request):
...
@@ -33,11 +33,11 @@ def basic_view(request):
if
request
.
method
==
'GET'
:
if
request
.
method
==
'GET'
:
return
{
'method'
:
'GET'
}
return
{
'method'
:
'GET'
}
elif
request
.
method
==
'POST'
:
elif
request
.
method
==
'POST'
:
return
{
'method'
:
'POST'
,
'data'
:
request
.
DATA
}
return
{
'method'
:
'POST'
,
'data'
:
request
.
data
}
elif
request
.
method
==
'PUT'
:
elif
request
.
method
==
'PUT'
:
return
{
'method'
:
'PUT'
,
'data'
:
request
.
DATA
}
return
{
'method'
:
'PUT'
,
'data'
:
request
.
data
}
elif
request
.
method
==
'PATCH'
:
elif
request
.
method
==
'PATCH'
:
return
{
'method'
:
'PATCH'
,
'data'
:
request
.
DATA
}
return
{
'method'
:
'PATCH'
,
'data'
:
request
.
data
}
class
ErrorView
(
APIView
):
class
ErrorView
(
APIView
):
...
@@ -123,7 +123,7 @@ class TestCustomExceptionHandler(TestCase):
...
@@ -123,7 +123,7 @@ class TestCustomExceptionHandler(TestCase):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
DEFAULT_HANDLER
=
api_settings
.
EXCEPTION_HANDLER
self
.
DEFAULT_HANDLER
=
api_settings
.
EXCEPTION_HANDLER
def
exception_handler
(
exc
):
def
exception_handler
(
exc
,
request
):
return
Response
(
'Error!'
,
status
=
status
.
HTTP_400_BAD_REQUEST
)
return
Response
(
'Error!'
,
status
=
status
.
HTTP_400_BAD_REQUEST
)
api_settings
.
EXCEPTION_HANDLER
=
exception_handler
api_settings
.
EXCEPTION_HANDLER
=
exception_handler
...
...
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