aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--AUTHORS1
-rw-r--r--djangorestframework/compat.py43
-rw-r--r--djangorestframework/templatetags/add_query_param.py4
-rw-r--r--djangorestframework/views.py3
4 files changed, 42 insertions, 9 deletions
diff --git a/AUTHORS b/AUTHORS
index ad94b672..2b042344 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -36,6 +36,7 @@ Daniel Izquierdo <izquierdo>
Can Yavuz <tschan>
Shawn Lewis <shawnlewis>
Adam Ness <greylurk>
+<yetist>
THANKS TO:
diff --git a/djangorestframework/compat.py b/djangorestframework/compat.py
index c9ae3b93..0772e17b 100644
--- a/djangorestframework/compat.py
+++ b/djangorestframework/compat.py
@@ -65,15 +65,45 @@ except ImportError:
environ.update(request)
return WSGIRequest(environ)
-# django.views.generic.View (Django >= 1.3)
+# django.views.generic.View (1.3 <= Django < 1.4)
try:
from django.views.generic import View
- if not hasattr(View, 'head'):
+
+ if django.VERSION < (1, 4):
+ from django.utils.decorators import classonlymethod
+ from django.utils.functional import update_wrapper
+
# First implementation of Django class-based views did not include head method
# in base View class - https://code.djangoproject.com/ticket/15668
class ViewPlusHead(View):
- def head(self, request, *args, **kwargs):
- return self.get(request, *args, **kwargs)
+ @classonlymethod
+ def as_view(cls, **initkwargs):
+ """
+ Main entry point for a request-response process.
+ """
+ # sanitize keyword arguments
+ for key in initkwargs:
+ if key in cls.http_method_names:
+ raise TypeError(u"You tried to pass in the %s method name as a "
+ u"keyword argument to %s(). Don't do that."
+ % (key, cls.__name__))
+ if not hasattr(cls, key):
+ raise TypeError(u"%s() received an invalid keyword %r" % (
+ cls.__name__, key))
+
+ def view(request, *args, **kwargs):
+ self = cls(**initkwargs)
+ if hasattr(self, 'get') and not hasattr(self, 'head'):
+ self.head = self.get
+ return self.dispatch(request, *args, **kwargs)
+
+ # take name and docstring from class
+ update_wrapper(view, cls, updated=())
+
+ # and possible attributes set by decorators
+ # like csrf_exempt from dispatch
+ update_wrapper(view, cls.dispatch, assigned=())
+ return view
View = ViewPlusHead
except ImportError:
@@ -121,6 +151,8 @@ except ImportError:
def view(request, *args, **kwargs):
self = cls(**initkwargs)
+ if hasattr(self, 'get') and not hasattr(self, 'head'):
+ self.head = self.get
return self.dispatch(request, *args, **kwargs)
# take name and docstring from class
@@ -154,9 +186,6 @@ except ImportError:
#)
return http.HttpResponseNotAllowed(allowed_methods)
- def head(self, request, *args, **kwargs):
- return self.get(request, *args, **kwargs)
-
# PUT, DELETE do not require CSRF until 1.4. They should. Make it better.
if django.VERSION >= (1, 4):
from django.middleware.csrf import CsrfViewMiddleware
diff --git a/djangorestframework/templatetags/add_query_param.py b/djangorestframework/templatetags/add_query_param.py
index 4cf0133b..143d7b3f 100644
--- a/djangorestframework/templatetags/add_query_param.py
+++ b/djangorestframework/templatetags/add_query_param.py
@@ -4,7 +4,7 @@ register = Library()
def add_query_param(url, param):
- return unicode(URLObject(url).with_query(param))
+ return unicode(URLObject(url).add_query_param(*param.split('=')))
-register.filter('add_query_param', add_query_param)
+register.filter('add_query_param', add_query_param) \ No newline at end of file
diff --git a/djangorestframework/views.py b/djangorestframework/views.py
index 3657fd64..4aa6ca0c 100644
--- a/djangorestframework/views.py
+++ b/djangorestframework/views.py
@@ -156,6 +156,9 @@ class View(ResourceMixin, RequestMixin, ResponseMixin, AuthMixin, DjangoView):
description = _remove_leading_indent(description)
+ if not isinstance(description, unicode):
+ description = description.decode('UTF-8')
+
if html:
return self.markup_description(description)
return description