aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--djangorestframework/mixins.py73
-rw-r--r--djangorestframework/tests/renderers.py3
-rw-r--r--djangorestframework/views.py40
3 files changed, 39 insertions, 77 deletions
diff --git a/djangorestframework/mixins.py b/djangorestframework/mixins.py
index 3142b093..d1014a84 100644
--- a/djangorestframework/mixins.py
+++ b/djangorestframework/mixins.py
@@ -11,13 +11,10 @@ from djangorestframework import status
from djangorestframework.renderers import BaseRenderer
from djangorestframework.resources import Resource, FormResource, ModelResource
from djangorestframework.response import Response, ImmediateResponse
-from djangorestframework.request import Request
__all__ = (
# Base behavior mixins
- 'RequestMixin',
- 'ResponseMixin',
'PermissionsMixin',
'ResourceMixin',
# Model behavior mixins
@@ -30,76 +27,6 @@ __all__ = (
)
-########## Request Mixin ##########
-
-class RequestMixin(object):
- """
- `Mixin` class enabling the use of :class:`request.Request` in your views.
- """
-
- request_class = Request
- """
- The class to use as a wrapper for the original request object.
- """
-
- def create_request(self, request):
- """
- Creates and returns an instance of :class:`request.Request`.
- This new instance wraps the `request` passed as a parameter, and use
- the parsers set on the view.
- """
- return self.request_class(request, parsers=self.parsers, authentication=self.authentication)
-
- @property
- def _parsed_media_types(self):
- """
- Return a list of all the media types that this view can parse.
- """
- return [parser.media_type for parser in self.parsers]
-
- @property
- def _default_parser(self):
- """
- Return the view's default parser class.
- """
- return self.parsers[0]
-
-
-########## ResponseMixin ##########
-
-class ResponseMixin(object):
- """
- `Mixin` class enabling the use of :class:`response.Response` in your views.
- """
-
- renderers = ()
- """
- The set of response renderers that the view can handle.
- Should be a tuple/list of classes as described in the :mod:`renderers` module.
- """
-
- @property
- def _rendered_media_types(self):
- """
- Return an list of all the media types that this response can render.
- """
- return [renderer.media_type for renderer in self.renderers]
-
- @property
- def _rendered_formats(self):
- """
- Return a list of all the formats that this response can render.
- """
- return [renderer.format for renderer in self.renderers]
-
- @property
- def _default_renderer(self):
- """
- Return the response's default renderer class.
- """
- return self.renderers[0]
-
-
########## Permissions Mixin ##########
class PermissionsMixin(object):
diff --git a/djangorestframework/tests/renderers.py b/djangorestframework/tests/renderers.py
index fce4af64..0e160606 100644
--- a/djangorestframework/tests/renderers.py
+++ b/djangorestframework/tests/renderers.py
@@ -6,7 +6,6 @@ from django.test import TestCase
from djangorestframework import status
from djangorestframework.compat import View as DjangoView
from djangorestframework.response import Response
-from djangorestframework.mixins import ResponseMixin
from djangorestframework.views import View
from djangorestframework.renderers import BaseRenderer, JSONRenderer, YAMLRenderer, \
XMLRenderer, JSONPRenderer, DocumentingHTMLRenderer
@@ -40,7 +39,7 @@ class RendererB(BaseRenderer):
return RENDERER_B_SERIALIZER(obj)
-class MockView(ResponseMixin, DjangoView):
+class MockView(View):
renderers = (RendererA, RendererB)
def get(self, request, **kwargs):
diff --git a/djangorestframework/views.py b/djangorestframework/views.py
index 8fe5f99a..f6a7a3bf 100644
--- a/djangorestframework/views.py
+++ b/djangorestframework/views.py
@@ -12,6 +12,7 @@ from django.views.decorators.csrf import csrf_exempt
from djangorestframework.compat import View as DjangoView, apply_markdown
from djangorestframework.response import Response, ImmediateResponse
+from djangorestframework.request import Request
from djangorestframework.mixins import *
from djangorestframework import resources, renderers, parsers, authentication, permissions, status
@@ -67,7 +68,7 @@ _resource_classes = (
)
-class View(ResourceMixin, RequestMixin, ResponseMixin, PermissionsMixin, DjangoView):
+class View(ResourceMixin, PermissionsMixin, DjangoView):
"""
Handles incoming requests and maps them to REST operations.
Performs request deserialization, response serialization, authentication and input validation.
@@ -187,6 +188,41 @@ class View(ResourceMixin, RequestMixin, ResponseMixin, PermissionsMixin, DjangoV
}
raise ImmediateResponse(content, status.HTTP_405_METHOD_NOT_ALLOWED)
+ @property
+ def _parsed_media_types(self):
+ """
+ Return a list of all the media types that this view can parse.
+ """
+ return [parser.media_type for parser in self.parsers]
+
+ @property
+ def _default_parser(self):
+ """
+ Return the view's default parser class.
+ """
+ return self.parsers[0]
+
+ @property
+ def _rendered_media_types(self):
+ """
+ Return an list of all the media types that this response can render.
+ """
+ return [renderer.media_type for renderer in self.renderers]
+
+ @property
+ def _rendered_formats(self):
+ """
+ Return a list of all the formats that this response can render.
+ """
+ return [renderer.format for renderer in self.renderers]
+
+ @property
+ def _default_renderer(self):
+ """
+ Return the response's default renderer class.
+ """
+ return self.renderers[0]
+
def initial(self, request, *args, **kargs):
"""
This method is a hook for any code that needs to run prior to
@@ -213,7 +249,7 @@ class View(ResourceMixin, RequestMixin, ResponseMixin, PermissionsMixin, DjangoV
# all other authentication is CSRF exempt.
@csrf_exempt
def dispatch(self, request, *args, **kwargs):
- request = self.create_request(request)
+ request = Request(request, parsers=self.parsers, authentication=self.authentication)
self.request = request
self.args = args