aboutsummaryrefslogtreecommitdiffstats
path: root/djangorestframework/views.py
diff options
context:
space:
mode:
authorTom Christie2012-02-20 09:36:03 +0000
committerTom Christie2012-02-20 09:36:03 +0000
commit21fcd3a90631e96e3fa210dd526abab9571ad6e1 (patch)
tree89de366aeb125596bf00d811cd8a409246c3c9e4 /djangorestframework/views.py
parentfbf76c87affc88f04bb0d0acaecc6af6442ba921 (diff)
downloaddjango-rest-framework-21fcd3a90631e96e3fa210dd526abab9571ad6e1.tar.bz2
Some cleanup
Diffstat (limited to 'djangorestframework/views.py')
-rw-r--r--djangorestframework/views.py29
1 files changed, 14 insertions, 15 deletions
diff --git a/djangorestframework/views.py b/djangorestframework/views.py
index 93e2d3a3..95fa119d 100644
--- a/djangorestframework/views.py
+++ b/djangorestframework/views.py
@@ -7,13 +7,12 @@ By setting or modifying class attributes on your view, you change it's predefine
import re
from django.core.urlresolvers import set_script_prefix, get_script_prefix
-from django.http import HttpResponse
from django.utils.html import escape
from django.utils.safestring import mark_safe
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.response import ImmediateResponse
from djangorestframework.mixins import *
from djangorestframework.utils import allowed_methods
from djangorestframework import resources, renderers, parsers, authentication, permissions, status
@@ -163,6 +162,9 @@ class View(ResourceMixin, RequestMixin, ResponseMixin, AuthMixin, DjangoView):
return description
def markup_description(self, description):
+ """
+ Apply HTML markup to the description of this view.
+ """
if apply_markdown:
description = apply_markdown(description)
else:
@@ -171,11 +173,13 @@ class View(ResourceMixin, RequestMixin, ResponseMixin, AuthMixin, DjangoView):
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 ImmediateResponse(
- {'detail': 'Method \'%s\' not allowed on this resource.' % request.method},
- status=status.HTTP_405_METHOD_NOT_ALLOWED)
+ content = {
+ 'detail': "Method '%s' not allowed on this resource." % request.method
+ }
+ raise ImmediateResponse(content, status.HTTP_405_METHOD_NOT_ALLOWED)
def initial(self, request, *args, **kargs):
"""
@@ -211,17 +215,12 @@ class View(ResourceMixin, RequestMixin, ResponseMixin, AuthMixin, DjangoView):
# all other authentication is CSRF exempt.
@csrf_exempt
def dispatch(self, request, *args, **kwargs):
- self.request = request
+ self.request = self.create_request(request)
self.args = args
self.kwargs = kwargs
try:
- # Get a custom request, built form the original request instance
- self.request = request = self.create_request(request)
-
- # `initial` is the opportunity to temper with the request,
- # even completely replace it.
- self.request = request = self.initial(request, *args, **kwargs)
+ self.initial(request, *args, **kwargs)
# Authenticate and check request has the relevant permissions
self._check_permissions()
@@ -231,7 +230,7 @@ class View(ResourceMixin, RequestMixin, ResponseMixin, AuthMixin, DjangoView):
handler = getattr(self, request.method.lower(), self.http_method_not_allowed)
else:
handler = self.http_method_not_allowed
-
+
# TODO: should we enforce HttpResponse, like Django does ?
response = handler(request, *args, **kwargs)
@@ -239,7 +238,7 @@ class View(ResourceMixin, RequestMixin, ResponseMixin, AuthMixin, DjangoView):
self.response = response = self.prepare_response(response)
# Pre-serialize filtering (eg filter complex objects into natively serializable types)
- # TODO: ugly hack to handle both HttpResponse and Response.
+ # TODO: ugly hack to handle both HttpResponse and Response.
if hasattr(response, 'raw_content'):
response.raw_content = self.filter_response(response.raw_content)
else: