aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/compat.py
diff options
context:
space:
mode:
authorTom Christie2013-04-23 11:59:13 +0100
committerTom Christie2013-04-23 11:59:13 +0100
commit835d3f89d37b873b2ef96dc7d71922b035b07328 (patch)
treebee0cdaac6e4fcaefd7fd83e9b9210d103e379af /rest_framework/compat.py
parent4bf1a09baeb885863e6028b97c2d51b26fb18534 (diff)
parentd75cebf75696602170a9d282d4b114d01d6e5d8e (diff)
downloaddjango-rest-framework-835d3f89d37b873b2ef96dc7d71922b035b07328.tar.bz2
Merge remove-django-generics
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 067e9018..3828555b 100644
--- a/rest_framework/compat.py
+++ b/rest_framework/compat.py
@@ -87,9 +87,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
@@ -97,6 +95,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):
"""
@@ -126,11 +126,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):