aboutsummaryrefslogtreecommitdiffstats
path: root/djangorestframework/views.py
diff options
context:
space:
mode:
authorTom Christie2011-05-12 12:55:13 +0100
committerTom Christie2011-05-12 12:55:13 +0100
commit15f9e7c56699d31043782045a9fe47c354f612cb (patch)
tree2c58441416a877d0afba22d85aea691190a17fa1 /djangorestframework/views.py
parent4d126796752cc3c79a24fd9caed49da6c525096f (diff)
downloaddjango-rest-framework-15f9e7c56699d31043782045a9fe47c354f612cb.tar.bz2
refactoring resource specfic stuff into ResourceMixin - validators now defunct
Diffstat (limited to 'djangorestframework/views.py')
-rw-r--r--djangorestframework/views.py25
1 files changed, 7 insertions, 18 deletions
diff --git a/djangorestframework/views.py b/djangorestframework/views.py
index 3ce4e1d6..3abf101c 100644
--- a/djangorestframework/views.py
+++ b/djangorestframework/views.py
@@ -17,7 +17,7 @@ __all__ = (
-class BaseView(RequestMixin, ResponseMixin, AuthMixin, View):
+class BaseView(ResourceMixin, RequestMixin, ResponseMixin, AuthMixin, View):
"""Handles incoming requests and maps them to REST operations.
Performs request deserialization, response serialization, authentication and input validation."""
@@ -46,9 +46,6 @@ class BaseView(RequestMixin, ResponseMixin, AuthMixin, View):
# List of all permissions that must be checked.
permissions = ( permissions.FullAnonAccess, )
- # Optional form for input validation and presentation of HTML formatted responses.
- form = None
-
# Allow name and description for the Resource to be set explicitly,
# overiding the default classname/docstring behaviour.
# These are used for documentation in the standard html and text renderers.
@@ -60,22 +57,13 @@ class BaseView(RequestMixin, ResponseMixin, AuthMixin, View):
return [method.upper() for method in self.http_method_names if hasattr(self, method)]
def http_method_not_allowed(self, request, *args, **kwargs):
- """Return an HTTP 405 error if an operation is called which does not have a handler method."""
+ """
+ Return an HTTP 405 error if an operation is called which does not have a handler method.
+ """
raise ErrorResponse(status.HTTP_405_METHOD_NOT_ALLOWED,
{'detail': 'Method \'%s\' not allowed on this resource.' % self.method})
- def cleanup_response(self, data):
- """Perform any resource-specific data filtering prior to the standard HTTP
- content-type serialization.
-
- Eg filter complex objects that cannot be serialized by json/xml/etc into basic objects that can.
-
- TODO: This is going to be removed. I think that the 'fields' behaviour is going to move into
- the RendererMixin and Renderer classes."""
- return data
-
-
# Note: session based authentication is explicitly CSRF validated,
# all other authentication is CSRF exempt.
@csrf_exempt
@@ -92,7 +80,7 @@ class BaseView(RequestMixin, ResponseMixin, AuthMixin, View):
try:
# If using a form POST with '_method'/'_content'/'_content_type' overrides, then alter
# self.method, self.content_type, self.RAW_CONTENT & self.CONTENT appropriately.
- self.perform_form_overloading()
+ self._perform_form_overloading()
# Authenticate and check request is has the relevant permissions
self._check_permissions()
@@ -114,13 +102,14 @@ class BaseView(RequestMixin, ResponseMixin, AuthMixin, View):
response = Response(status.HTTP_204_NO_CONTENT)
# Pre-serialize filtering (eg filter complex objects into natively serializable types)
- response.cleaned_content = self.resource.object_to_serializable(response.raw_content)
+ response.cleaned_content = self.object_to_data(response.raw_content)
except ErrorResponse, exc:
response = exc.response
except:
import traceback
traceback.print_exc()
+ raise
# Always add these headers.
#