aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--djangorestframework/authenticators.py5
-rw-r--r--djangorestframework/modelresource.py18
-rw-r--r--djangorestframework/resource.py14
-rw-r--r--djangorestframework/tests/accept.py2
-rw-r--r--djangorestframework/tests/authentication.py2
-rw-r--r--djangorestframework/tests/files.py7
-rw-r--r--djangorestframework/tests/reverse.py2
7 files changed, 23 insertions, 27 deletions
diff --git a/djangorestframework/authenticators.py b/djangorestframework/authenticators.py
index e382de10..e8331cc7 100644
--- a/djangorestframework/authenticators.py
+++ b/djangorestframework/authenticators.py
@@ -28,8 +28,9 @@ class BaseAuthenticator(object):
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.
- The authentication context is passed to the method calls eg Resource.get(request, auth) in order to
- allow them to apply any more fine grained permission checking at the point the response is being generated.
+ The authentication context is available to the method calls eg Resource.get(request)
+ 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."""
return None
diff --git a/djangorestframework/modelresource.py b/djangorestframework/modelresource.py
index b0a4b1c1..23a87e65 100644
--- a/djangorestframework/modelresource.py
+++ b/djangorestframework/modelresource.py
@@ -341,7 +341,7 @@ class ModelResource(Resource):
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
# translated related_field into related_field_id
@@ -350,7 +350,7 @@ class ModelResource(Resource):
kwargs[related_name + '_id'] = 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:
instance = self.model(pk=args[-1], **all_kw_args)
else:
@@ -361,7 +361,7 @@ class ModelResource(Resource):
headers['Location'] = instance.get_absolute_url()
return Response(status.HTTP_201_CREATED, instance, headers)
- def get(self, request, auth, *args, **kwargs):
+ def get(self, request, *args, **kwargs):
try:
if args:
# If we have any none kwargs then assume the last represents the primrary key
@@ -374,7 +374,7 @@ class ModelResource(Resource):
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
try:
if args:
@@ -384,16 +384,16 @@ class ModelResource(Resource):
# Otherwise assume the kwargs uniquely identify the model
instance = self.model.objects.get(**kwargs)
- for (key, val) in content.items():
+ for (key, val) in self.CONTENT.items():
setattr(instance, key, val)
except self.model.DoesNotExist:
- instance = self.model(**content)
+ instance = self.model(**self.CONTENT)
instance.save()
instance.save()
return instance
- def delete(self, request, auth, *args, **kwargs):
+ def delete(self, request, *args, **kwargs):
try:
if args:
# If we have any none kwargs then assume the last represents the primrary key
@@ -413,7 +413,7 @@ class RootModelResource(ModelResource):
allowed_methods = ('GET', 'POST')
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()
return queryset.filter(**kwargs)
@@ -427,7 +427,7 @@ class QueryModelResource(ModelResource):
def get_form(self, data=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()
return queryset.filer(**kwargs)
diff --git a/djangorestframework/resource.py b/djangorestframework/resource.py
index f4460c1e..0615a164 100644
--- a/djangorestframework/resource.py
+++ b/djangorestframework/resource.py
@@ -57,22 +57,22 @@ class Resource(RequestMixin, ResponseMixin, AuthMixin, View):
callmap = { 'GET': 'get', 'POST': 'post',
'PUT': 'put', 'DELETE': 'delete' }
- def get(self, request, auth, *args, **kwargs):
+ def get(self, request, *args, **kwargs):
"""Must be subclassed to be implemented."""
self.not_implemented('GET')
- def post(self, request, auth, content, *args, **kwargs):
+ def post(self, request, *args, **kwargs):
"""Must be subclassed to be implemented."""
self.not_implemented('POST')
- def put(self, request, auth, content, *args, **kwargs):
+ def put(self, request, *args, **kwargs):
"""Must be subclassed to be implemented."""
self.not_implemented('PUT')
- def delete(self, request, auth, *args, **kwargs):
+ def delete(self, request, *args, **kwargs):
"""Must be subclassed to be implemented."""
self.not_implemented('DELETE')
@@ -154,11 +154,7 @@ class Resource(RequestMixin, ResponseMixin, AuthMixin, View):
# Either generate the response data, deserializing and validating any request data
# 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.
- if self.method in ('PUT', 'POST'):
- response_obj = func(request, auth_context, self.CONTENT, *args, **kwargs)
-
- else:
- response_obj = func(request, auth_context, *args, **kwargs)
+ response_obj = func(request, *args, **kwargs)
# Allow return value to be either Response, or an object, or None
if isinstance(response_obj, Response):
diff --git a/djangorestframework/tests/accept.py b/djangorestframework/tests/accept.py
index f2a21277..726e1252 100644
--- a/djangorestframework/tests/accept.py
+++ b/djangorestframework/tests/accept.py
@@ -20,7 +20,7 @@ class UserAgentMungingTest(TestCase):
def setUp(self):
class MockResource(Resource):
anon_allowed_methods = allowed_methods = ('GET',)
- def get(self, request, auth):
+ def get(self, request):
return {'a':1, 'b':2, 'c':3}
self.req = RequestFactory()
self.MockResource = MockResource
diff --git a/djangorestframework/tests/authentication.py b/djangorestframework/tests/authentication.py
index af9c34ca..b2bc4446 100644
--- a/djangorestframework/tests/authentication.py
+++ b/djangorestframework/tests/authentication.py
@@ -15,7 +15,7 @@ except ImportError:
class MockResource(Resource):
allowed_methods = ('POST',)
- def post(self, request, auth, content):
+ def post(self, request):
return {'a':1, 'b':2, 'c':3}
urlpatterns = patterns('',
diff --git a/djangorestframework/tests/files.py b/djangorestframework/tests/files.py
index e155f181..dd4689a6 100644
--- a/djangorestframework/tests/files.py
+++ b/djangorestframework/tests/files.py
@@ -19,10 +19,9 @@ class UploadFilesTests(TestCase):
allowed_methods = anon_allowed_methods = ('POST',)
form = FileForm
- def post(self, request, auth, content, *args, **kwargs):
- #self.uploaded = content.file
- return {'FILE_NAME': content['file'].name,
- 'FILE_CONTENT': content['file'].read()}
+ def post(self, request, *args, **kwargs):
+ return {'FILE_NAME': self.CONTENT['file'].name,
+ 'FILE_CONTENT': self.CONTENT['file'].read()}
file = StringIO.StringIO('stuff')
file.name = 'stuff.txt'
diff --git a/djangorestframework/tests/reverse.py b/djangorestframework/tests/reverse.py
index a862e39a..f6a3ea51 100644
--- a/djangorestframework/tests/reverse.py
+++ b/djangorestframework/tests/reverse.py
@@ -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"""
anon_allowed_methods = ('GET',)
- def get(self, request, auth):
+ def get(self, request):
return reverse('another')
urlpatterns = patterns('',