mirror of
				https://github.com/encode/django-rest-framework.git
				synced 2025-11-04 09:57:55 +03:00 
			
		
		
		
	depercate auth and content arguments to the request handler methods - yea :)
This commit is contained in:
		
							parent
							
								
									6096b50dbe
								
							
						
					
					
						commit
						18bbda84b9
					
				| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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('',
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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'
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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('',
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user