aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/compat.py
diff options
context:
space:
mode:
authorTom Christie2013-05-07 05:08:28 -0700
committerTom Christie2013-05-07 05:08:28 -0700
commit5356af8651fccacf5524add33569dd84d9e78646 (patch)
tree8f7145c0a4cfeab61e1e523409b82091f44dfdbb /rest_framework/compat.py
parent287ff43cdd85a5c2275205bf37e19dea3f69ad01 (diff)
parent0f00da848d9a8d25a0049231e9794da71a96662b (diff)
downloaddjango-rest-framework-5356af8651fccacf5524add33569dd84d9e78646.tar.bz2
Merge pull request #808 from tomchristie/2.3
2.3
Diffstat (limited to 'rest_framework/compat.py')
-rw-r--r--rest_framework/compat.py20
1 files changed, 12 insertions, 8 deletions
diff --git a/rest_framework/compat.py b/rest_framework/compat.py
index f8e4e7ca..cd39f544 100644
--- a/rest_framework/compat.py
+++ b/rest_framework/compat.py
@@ -88,9 +88,7 @@ else:
raise ImportError("User model is not to be found.")
-# First implementation of Django class-based views did not include head method
-# in base View class - https://code.djangoproject.com/ticket/15668
-if django.VERSION >= (1, 4):
+if django.VERSION >= (1, 5):
from django.views.generic import View
else:
from django.views.generic import View as _View
@@ -98,6 +96,8 @@ else:
from django.utils.functional import update_wrapper
class View(_View):
+ # 1.3 does not include head method in base View class
+ # See: https://code.djangoproject.com/ticket/15668
@classonlymethod
def as_view(cls, **initkwargs):
"""
@@ -127,11 +127,15 @@ else:
update_wrapper(view, cls.dispatch, assigned=())
return view
-# Taken from @markotibold's attempt at supporting PATCH.
-# https://github.com/markotibold/django-rest-framework/tree/patch
-http_method_names = set(View.http_method_names)
-http_method_names.add('patch')
-View.http_method_names = list(http_method_names) # PATCH method is not implemented by Django
+ # _allowed_methods only present from 1.5 onwards
+ def _allowed_methods(self):
+ return [m.upper() for m in self.http_method_names if hasattr(self, m)]
+
+
+# PATCH method is not implemented by Django
+if 'patch' not in View.http_method_names:
+ View.http_method_names = View.http_method_names + ['patch']
+
# PUT, DELETE do not require CSRF until 1.4. They should. Make it better.
if django.VERSION >= (1, 4):