From ee8b810b977572e39dc6acf4d13cc5e05f4d65ee Mon Sep 17 00:00:00 2001 From: Krzysztof Jurewicz Date: Tue, 21 May 2013 18:01:29 +0200 Subject: [PATCH] =?UTF-8?q?Fixed=20#20478=20=E2=80=93=20Added=20support=20?= =?UTF-8?q?for=20HTTP=20PATCH=20method=20in=20generic=20views.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- django/views/generic/base.py | 5 ++++- docs/ref/class-based-views/base.txt | 2 +- docs/releases/1.6.txt | 3 +++ tests/generic_views/test_base.py | 6 ++++++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/django/views/generic/base.py b/django/views/generic/base.py index d50d6bbc559..286a18d0f29 100644 --- a/django/views/generic/base.py +++ b/django/views/generic/base.py @@ -30,7 +30,7 @@ class View(object): dispatch-by-method and simple sanity checking. """ - http_method_names = ['get', 'post', 'put', 'delete', 'head', 'options', 'trace'] + http_method_names = ['get', 'post', 'put', 'patch', 'delete', 'head', 'options', 'trace'] def __init__(self, **kwargs): """ @@ -206,3 +206,6 @@ class RedirectView(View): def put(self, request, *args, **kwargs): return self.get(request, *args, **kwargs) + + def patch(self, request, *args, **kwargs): + return self.get(request, *args, **kwargs) diff --git a/docs/ref/class-based-views/base.txt b/docs/ref/class-based-views/base.txt index 94bf6e12f93..17862978e79 100644 --- a/docs/ref/class-based-views/base.txt +++ b/docs/ref/class-based-views/base.txt @@ -55,7 +55,7 @@ View Default:: - ['get', 'post', 'put', 'delete', 'head', 'options', 'trace'] + ['get', 'post', 'put', 'patch', 'delete', 'head', 'options', 'trace'] **Methods** diff --git a/docs/releases/1.6.txt b/docs/releases/1.6.txt index a1a29471a32..3bc5a0996c2 100644 --- a/docs/releases/1.6.txt +++ b/docs/releases/1.6.txt @@ -258,6 +258,9 @@ Minor features methods returning the first or last object matching the filters. Returns ``None`` if there are no objects matching. +* :class:`~django.views.generic.base.View` and + :class:`~django.views.generic.base.RedirectView` now support HTTP PATCH method. + Backwards incompatible changes in 1.6 ===================================== diff --git a/tests/generic_views/test_base.py b/tests/generic_views/test_base.py index 9080015f4fb..ffd9b1b480f 100644 --- a/tests/generic_views/test_base.py +++ b/tests/generic_views/test_base.py @@ -384,6 +384,12 @@ class RedirectViewTest(unittest.TestCase): self.assertEqual(response.status_code, 301) self.assertEqual(response.url, '/bar/') + def test_redirect_PATCH(self): + "Default is a permanent redirect" + response = RedirectView.as_view(url='/bar/')(self.rf.patch('/foo/')) + self.assertEqual(response.status_code, 301) + self.assertEqual(response.url, '/bar/') + def test_redirect_DELETE(self): "Default is a permanent redirect" response = RedirectView.as_view(url='/bar/')(self.rf.delete('/foo/'))