aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--djangorestframework/authenticators.py2
-rw-r--r--djangorestframework/emitters.py8
-rw-r--r--djangorestframework/resource.py98
-rw-r--r--examples/blogpost/tests.py6
-rw-r--r--examples/pygments_api/tests.py6
5 files changed, 59 insertions, 61 deletions
diff --git a/djangorestframework/authenticators.py b/djangorestframework/authenticators.py
index 29fbb818..74d9931a 100644
--- a/djangorestframework/authenticators.py
+++ b/djangorestframework/authenticators.py
@@ -68,7 +68,7 @@ class UserLoggedInAuthenticator(BaseAuthenticator):
if request.method.upper() == 'POST':
# Temporarily replace request.POST with .RAW_CONTENT,
# so that we use our more generic request parsing
- request._post = self.mixin.RAW_CONTENT
+ request._post = self.view.RAW_CONTENT
resp = CsrfViewMiddleware().process_view(request, None, (), {})
del(request._post)
if resp is not None: # csrf failed
diff --git a/djangorestframework/emitters.py b/djangorestframework/emitters.py
index 2702758b..d2b06c13 100644
--- a/djangorestframework/emitters.py
+++ b/djangorestframework/emitters.py
@@ -9,8 +9,14 @@ from django.template import RequestContext, loader
from django.utils import simplejson as json
from django import forms
-from decimal import Decimal
+from djangorestframework.utils import dict2xml, url_resolves
+from djangorestframework.markdownwrapper import apply_markdown
+from djangorestframework.breadcrumbs import get_breadcrumbs
+from djangorestframework.description import get_name, get_description
+from djangorestframework import status
+from decimal import Decimal
+import string
# TODO: Rename verbose to something more appropriate
# TODO: Maybe None could be handled more cleanly. It'd be nice if it was handled by default,
diff --git a/djangorestframework/resource.py b/djangorestframework/resource.py
index fbf51cfc..fdbce8b5 100644
--- a/djangorestframework/resource.py
+++ b/djangorestframework/resource.py
@@ -77,55 +77,59 @@ class Resource(RequestMixin, ResponseMixin, AuthMixin, View):
# all other authentication is CSRF exempt.
@csrf_exempt
def dispatch(self, request, *args, **kwargs):
- self.request = request
- self.args = args
- self.kwargs = kwargs
-
- # Calls to 'reverse' will not be fully qualified unless we set the scheme/host/port here.
- prefix = '%s://%s' % (request.is_secure() and 'https' or 'http', request.get_host())
- set_script_prefix(prefix)
-
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()
-
- # Authenticate and check request is has the relevant permissions
- self.check_permissions()
-
- # Get the appropriate handler method
- if self.method.lower() in self.http_method_names:
- handler = getattr(self, self.method.lower(), self.http_method_not_allowed)
- # If a previously defined method has been disabled
- if handler is None:
+ self.request = request
+ self.args = args
+ self.kwargs = kwargs
+
+ # Calls to 'reverse' will not be fully qualified unless we set the scheme/host/port here.
+ prefix = '%s://%s' % (request.is_secure() and 'https' or 'http', request.get_host())
+ set_script_prefix(prefix)
+
+ 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()
+
+ # Authenticate and check request is has the relevant permissions
+ self.check_permissions()
+
+ # Get the appropriate handler method
+ if self.method.lower() in self.http_method_names:
+ handler = getattr(self, self.method.lower(), self.http_method_not_allowed)
+ # If a previously defined method has been disabled
+ if handler is None:
+ handler = self.http_method_not_allowed
+ else:
handler = self.http_method_not_allowed
- else:
- handler = self.http_method_not_allowed
-
- response_obj = handler(request, *args, **kwargs)
-
- # Allow return value to be either Response, or an object, or None
- if isinstance(response_obj, Response):
- response = response_obj
- elif response_obj is not None:
- response = Response(status.HTTP_200_OK, response_obj)
- else:
- response = Response(status.HTTP_204_NO_CONTENT)
-
- # Pre-serialize filtering (eg filter complex objects into natively serializable types)
- response.cleaned_content = self.cleanup_response(response.raw_content)
-
- except ErrorResponse, exc:
- response = exc.response
-
- # Always add these headers.
- #
- # TODO - this isn't actually the correct way to set the vary header,
- # also it's currently sub-obtimal for HTTP caching - need to sort that out.
- response.headers['Allow'] = ', '.join(self.allowed_methods)
- response.headers['Vary'] = 'Authenticate, Accept'
-
- return self.emit(response)
+
+ response_obj = handler(request, *args, **kwargs)
+
+ # Allow return value to be either Response, or an object, or None
+ if isinstance(response_obj, Response):
+ response = response_obj
+ elif response_obj is not None:
+ response = Response(status.HTTP_200_OK, response_obj)
+ else:
+ response = Response(status.HTTP_204_NO_CONTENT)
+
+ # Pre-serialize filtering (eg filter complex objects into natively serializable types)
+ response.cleaned_content = self.cleanup_response(response.raw_content)
+
+ except ErrorResponse, exc:
+ response = exc.response
+
+ # Always add these headers.
+ #
+ # TODO - this isn't actually the correct way to set the vary header,
+ # also it's currently sub-obtimal for HTTP caching - need to sort that out.
+ response.headers['Allow'] = ', '.join(self.allowed_methods)
+ response.headers['Vary'] = 'Authenticate, Accept'
+
+ return self.emit(response)
+ except:
+ import traceback
+ traceback.print_exc()
diff --git a/examples/blogpost/tests.py b/examples/blogpost/tests.py
index 494478d8..9b9a682f 100644
--- a/examples/blogpost/tests.py
+++ b/examples/blogpost/tests.py
@@ -3,10 +3,7 @@
from django.core.urlresolvers import reverse
from django.test import TestCase
-<<<<<<< local
-=======
from django.core.urlresolvers import reverse
->>>>>>> other
from django.utils import simplejson as json
from djangorestframework.compat import RequestFactory
@@ -170,10 +167,7 @@ class AllowedMethodsTests(TestCase):
#above testcases need to probably moved to the core
-<<<<<<< local
-=======
->>>>>>> other
class TestRotation(TestCase):
"""For the example the maximum amount of Blogposts is capped off at views.MAX_POSTS.
diff --git a/examples/pygments_api/tests.py b/examples/pygments_api/tests.py
index 766defc3..6eb69da5 100644
--- a/examples/pygments_api/tests.py
+++ b/examples/pygments_api/tests.py
@@ -1,18 +1,12 @@
from django.test import TestCase
from django.utils import simplejson as json
-<<<<<<< local
-=======
->>>>>>> other
from djangorestframework.compat import RequestFactory
from pygments_api import views
import tempfile, shutil
-<<<<<<< local
-=======
->>>>>>> other
class TestPygmentsExample(TestCase):