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
18bbda84
Commit
18bbda84
authored
Apr 11, 2011
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
depercate auth and content arguments to the request handler methods - yea :)
parent
6096b50d
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
23 additions
and
27 deletions
+23
-27
djangorestframework/authenticators.py
+3
-2
djangorestframework/modelresource.py
+9
-9
djangorestframework/resource.py
+5
-9
djangorestframework/tests/accept.py
+1
-1
djangorestframework/tests/authentication.py
+1
-1
djangorestframework/tests/files.py
+3
-4
djangorestframework/tests/reverse.py
+1
-1
No files found.
djangorestframework/authenticators.py
View file @
18bbda84
...
@@ -28,8 +28,9 @@ class BaseAuthenticator(object):
...
@@ -28,8 +28,9 @@ class BaseAuthenticator(object):
The default permission checking on Resource will use the allowed_methods attribute
The default permission checking on Resource will use the allowed_methods attribute
for permissions if the authentication context is not None, and use anon_allowed_methods otherwise.
for permissions if the authentication context is not None, and use anon_allowed_methods otherwise.
The authentication context is passed to the method calls eg Resource.get(request, auth) in order to
The authentication context is available to the method calls eg Resource.get(request)
allow them to apply any more fine grained permission checking at the point the response is being generated.
by accessing self.auth in order to allow them to apply any more fine grained permission
checking at the point the response is being generated.
This function must be overridden to be implemented."""
This function must be overridden to be implemented."""
return
None
return
None
...
...
djangorestframework/modelresource.py
View file @
18bbda84
...
@@ -341,7 +341,7 @@ class ModelResource(Resource):
...
@@ -341,7 +341,7 @@ class ModelResource(Resource):
return
_any
(
data
,
self
.
fields
)
return
_any
(
data
,
self
.
fields
)
def
post
(
self
,
request
,
auth
,
content
,
*
args
,
**
kwargs
):
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
# TODO: test creation on a non-existing resource url
# TODO: test creation on a non-existing resource url
# translated related_field into related_field_id
# translated related_field into related_field_id
...
@@ -350,7 +350,7 @@ class ModelResource(Resource):
...
@@ -350,7 +350,7 @@ class ModelResource(Resource):
kwargs
[
related_name
+
'_id'
]
=
kwargs
[
related_name
]
kwargs
[
related_name
+
'_id'
]
=
kwargs
[
related_name
]
del
kwargs
[
related_name
]
del
kwargs
[
related_name
]
all_kw_args
=
dict
(
content
.
items
()
+
kwargs
.
items
())
all_kw_args
=
dict
(
self
.
CONTENT
.
items
()
+
kwargs
.
items
())
if
args
:
if
args
:
instance
=
self
.
model
(
pk
=
args
[
-
1
],
**
all_kw_args
)
instance
=
self
.
model
(
pk
=
args
[
-
1
],
**
all_kw_args
)
else
:
else
:
...
@@ -361,7 +361,7 @@ class ModelResource(Resource):
...
@@ -361,7 +361,7 @@ class ModelResource(Resource):
headers
[
'Location'
]
=
instance
.
get_absolute_url
()
headers
[
'Location'
]
=
instance
.
get_absolute_url
()
return
Response
(
status
.
HTTP_201_CREATED
,
instance
,
headers
)
return
Response
(
status
.
HTTP_201_CREATED
,
instance
,
headers
)
def
get
(
self
,
request
,
auth
,
*
args
,
**
kwargs
):
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
try
:
try
:
if
args
:
if
args
:
# If we have any none kwargs then assume the last represents the primrary key
# If we have any none kwargs then assume the last represents the primrary key
...
@@ -374,7 +374,7 @@ class ModelResource(Resource):
...
@@ -374,7 +374,7 @@ class ModelResource(Resource):
return
instance
return
instance
def
put
(
self
,
request
,
auth
,
content
,
*
args
,
**
kwargs
):
def
put
(
self
,
request
,
*
args
,
**
kwargs
):
# TODO: update on the url of a non-existing resource url doesn't work correctly at the moment - will end up with a new url
# TODO: update on the url of a non-existing resource url doesn't work correctly at the moment - will end up with a new url
try
:
try
:
if
args
:
if
args
:
...
@@ -384,16 +384,16 @@ class ModelResource(Resource):
...
@@ -384,16 +384,16 @@ class ModelResource(Resource):
# Otherwise assume the kwargs uniquely identify the model
# Otherwise assume the kwargs uniquely identify the model
instance
=
self
.
model
.
objects
.
get
(
**
kwargs
)
instance
=
self
.
model
.
objects
.
get
(
**
kwargs
)
for
(
key
,
val
)
in
content
.
items
():
for
(
key
,
val
)
in
self
.
CONTENT
.
items
():
setattr
(
instance
,
key
,
val
)
setattr
(
instance
,
key
,
val
)
except
self
.
model
.
DoesNotExist
:
except
self
.
model
.
DoesNotExist
:
instance
=
self
.
model
(
**
content
)
instance
=
self
.
model
(
**
self
.
CONTENT
)
instance
.
save
()
instance
.
save
()
instance
.
save
()
instance
.
save
()
return
instance
return
instance
def
delete
(
self
,
request
,
auth
,
*
args
,
**
kwargs
):
def
delete
(
self
,
request
,
*
args
,
**
kwargs
):
try
:
try
:
if
args
:
if
args
:
# If we have any none kwargs then assume the last represents the primrary key
# If we have any none kwargs then assume the last represents the primrary key
...
@@ -413,7 +413,7 @@ class RootModelResource(ModelResource):
...
@@ -413,7 +413,7 @@ class RootModelResource(ModelResource):
allowed_methods
=
(
'GET'
,
'POST'
)
allowed_methods
=
(
'GET'
,
'POST'
)
queryset
=
None
queryset
=
None
def
get
(
self
,
request
,
auth
,
*
args
,
**
kwargs
):
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
queryset
=
self
.
queryset
if
self
.
queryset
else
self
.
model
.
objects
.
all
()
queryset
=
self
.
queryset
if
self
.
queryset
else
self
.
model
.
objects
.
all
()
return
queryset
.
filter
(
**
kwargs
)
return
queryset
.
filter
(
**
kwargs
)
...
@@ -427,7 +427,7 @@ class QueryModelResource(ModelResource):
...
@@ -427,7 +427,7 @@ class QueryModelResource(ModelResource):
def
get_form
(
self
,
data
=
None
):
def
get_form
(
self
,
data
=
None
):
return
None
return
None
def
get
(
self
,
request
,
auth
,
*
args
,
**
kwargs
):
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
queryset
=
self
.
queryset
if
self
.
queryset
else
self
.
model
.
objects
.
all
()
queryset
=
self
.
queryset
if
self
.
queryset
else
self
.
model
.
objects
.
all
()
return
queryset
.
filer
(
**
kwargs
)
return
queryset
.
filer
(
**
kwargs
)
djangorestframework/resource.py
View file @
18bbda84
...
@@ -57,22 +57,22 @@ class Resource(RequestMixin, ResponseMixin, AuthMixin, View):
...
@@ -57,22 +57,22 @@ class Resource(RequestMixin, ResponseMixin, AuthMixin, View):
callmap
=
{
'GET'
:
'get'
,
'POST'
:
'post'
,
callmap
=
{
'GET'
:
'get'
,
'POST'
:
'post'
,
'PUT'
:
'put'
,
'DELETE'
:
'delete'
}
'PUT'
:
'put'
,
'DELETE'
:
'delete'
}
def
get
(
self
,
request
,
auth
,
*
args
,
**
kwargs
):
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
"""Must be subclassed to be implemented."""
"""Must be subclassed to be implemented."""
self
.
not_implemented
(
'GET'
)
self
.
not_implemented
(
'GET'
)
def
post
(
self
,
request
,
auth
,
content
,
*
args
,
**
kwargs
):
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
"""Must be subclassed to be implemented."""
"""Must be subclassed to be implemented."""
self
.
not_implemented
(
'POST'
)
self
.
not_implemented
(
'POST'
)
def
put
(
self
,
request
,
auth
,
content
,
*
args
,
**
kwargs
):
def
put
(
self
,
request
,
*
args
,
**
kwargs
):
"""Must be subclassed to be implemented."""
"""Must be subclassed to be implemented."""
self
.
not_implemented
(
'PUT'
)
self
.
not_implemented
(
'PUT'
)
def
delete
(
self
,
request
,
auth
,
*
args
,
**
kwargs
):
def
delete
(
self
,
request
,
*
args
,
**
kwargs
):
"""Must be subclassed to be implemented."""
"""Must be subclassed to be implemented."""
self
.
not_implemented
(
'DELETE'
)
self
.
not_implemented
(
'DELETE'
)
...
@@ -154,11 +154,7 @@ class Resource(RequestMixin, ResponseMixin, AuthMixin, View):
...
@@ -154,11 +154,7 @@ class Resource(RequestMixin, ResponseMixin, AuthMixin, View):
# Either generate the response data, deserializing and validating any request data
# Either generate the response data, deserializing and validating any request data
# TODO: This is going to change to: func(request, *args, **kwargs)
# TODO: This is going to change to: func(request, *args, **kwargs)
# That'll work out now that we have the lazily evaluated self.CONTENT property.
# That'll work out now that we have the lazily evaluated self.CONTENT property.
if
self
.
method
in
(
'PUT'
,
'POST'
):
response_obj
=
func
(
request
,
*
args
,
**
kwargs
)
response_obj
=
func
(
request
,
auth_context
,
self
.
CONTENT
,
*
args
,
**
kwargs
)
else
:
response_obj
=
func
(
request
,
auth_context
,
*
args
,
**
kwargs
)
# Allow return value to be either Response, or an object, or None
# Allow return value to be either Response, or an object, or None
if
isinstance
(
response_obj
,
Response
):
if
isinstance
(
response_obj
,
Response
):
...
...
djangorestframework/tests/accept.py
View file @
18bbda84
...
@@ -20,7 +20,7 @@ class UserAgentMungingTest(TestCase):
...
@@ -20,7 +20,7 @@ class UserAgentMungingTest(TestCase):
def
setUp
(
self
):
def
setUp
(
self
):
class
MockResource
(
Resource
):
class
MockResource
(
Resource
):
anon_allowed_methods
=
allowed_methods
=
(
'GET'
,)
anon_allowed_methods
=
allowed_methods
=
(
'GET'
,)
def
get
(
self
,
request
,
auth
):
def
get
(
self
,
request
):
return
{
'a'
:
1
,
'b'
:
2
,
'c'
:
3
}
return
{
'a'
:
1
,
'b'
:
2
,
'c'
:
3
}
self
.
req
=
RequestFactory
()
self
.
req
=
RequestFactory
()
self
.
MockResource
=
MockResource
self
.
MockResource
=
MockResource
...
...
djangorestframework/tests/authentication.py
View file @
18bbda84
...
@@ -15,7 +15,7 @@ except ImportError:
...
@@ -15,7 +15,7 @@ except ImportError:
class
MockResource
(
Resource
):
class
MockResource
(
Resource
):
allowed_methods
=
(
'POST'
,)
allowed_methods
=
(
'POST'
,)
def
post
(
self
,
request
,
auth
,
content
):
def
post
(
self
,
request
):
return
{
'a'
:
1
,
'b'
:
2
,
'c'
:
3
}
return
{
'a'
:
1
,
'b'
:
2
,
'c'
:
3
}
urlpatterns
=
patterns
(
''
,
urlpatterns
=
patterns
(
''
,
...
...
djangorestframework/tests/files.py
View file @
18bbda84
...
@@ -19,10 +19,9 @@ class UploadFilesTests(TestCase):
...
@@ -19,10 +19,9 @@ class UploadFilesTests(TestCase):
allowed_methods
=
anon_allowed_methods
=
(
'POST'
,)
allowed_methods
=
anon_allowed_methods
=
(
'POST'
,)
form
=
FileForm
form
=
FileForm
def
post
(
self
,
request
,
auth
,
content
,
*
args
,
**
kwargs
):
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
#self.uploaded = content.file
return
{
'FILE_NAME'
:
self
.
CONTENT
[
'file'
]
.
name
,
return
{
'FILE_NAME'
:
content
[
'file'
]
.
name
,
'FILE_CONTENT'
:
self
.
CONTENT
[
'file'
]
.
read
()}
'FILE_CONTENT'
:
content
[
'file'
]
.
read
()}
file
=
StringIO
.
StringIO
(
'stuff'
)
file
=
StringIO
.
StringIO
(
'stuff'
)
file
.
name
=
'stuff.txt'
file
.
name
=
'stuff.txt'
...
...
djangorestframework/tests/reverse.py
View file @
18bbda84
...
@@ -14,7 +14,7 @@ class MockResource(Resource):
...
@@ -14,7 +14,7 @@ class MockResource(Resource):
"""Mock resource which simply returns a URL, so that we can ensure that reversed URLs are fully qualified"""
"""Mock resource which simply returns a URL, so that we can ensure that reversed URLs are fully qualified"""
anon_allowed_methods
=
(
'GET'
,)
anon_allowed_methods
=
(
'GET'
,)
def
get
(
self
,
request
,
auth
):
def
get
(
self
,
request
):
return
reverse
(
'another'
)
return
reverse
(
'another'
)
urlpatterns
=
patterns
(
''
,
urlpatterns
=
patterns
(
''
,
...
...
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