Fixed #15739 -- Added support to RedirectView for HEAD, OPTIONS, POST, PUT and DELETE requests
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15992 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
ae5f3e7418
commit
62f37c69b0
|
@ -161,3 +161,18 @@ class RedirectView(View):
|
||||||
'request': self.request
|
'request': self.request
|
||||||
})
|
})
|
||||||
return http.HttpResponseGone()
|
return http.HttpResponseGone()
|
||||||
|
|
||||||
|
def head(self, request, *args, **kwargs):
|
||||||
|
return self.get(request, *args, **kwargs)
|
||||||
|
|
||||||
|
def post(self, request, *args, **kwargs):
|
||||||
|
return self.get(request, *args, **kwargs)
|
||||||
|
|
||||||
|
def options(self, request, *args, **kwargs):
|
||||||
|
return self.get(request, *args, **kwargs)
|
||||||
|
|
||||||
|
def delete(self, request, *args, **kwargs):
|
||||||
|
return self.get(request, *args, **kwargs)
|
||||||
|
|
||||||
|
def put(self, request, *args, **kwargs):
|
||||||
|
return self.get(request, *args, **kwargs)
|
||||||
|
|
|
@ -261,3 +261,33 @@ class RedirectViewTest(unittest.TestCase):
|
||||||
response = RedirectView.as_view(url='/bar/%(object_id)d/')(self.rf.get('/foo/42/'), object_id=42)
|
response = RedirectView.as_view(url='/bar/%(object_id)d/')(self.rf.get('/foo/42/'), object_id=42)
|
||||||
self.assertEqual(response.status_code, 301)
|
self.assertEqual(response.status_code, 301)
|
||||||
self.assertEqual(response['Location'], '/bar/42/')
|
self.assertEqual(response['Location'], '/bar/42/')
|
||||||
|
|
||||||
|
def test_redirect_POST(self):
|
||||||
|
"Default is a permanent redirect"
|
||||||
|
response = RedirectView.as_view(url='/bar/')(self.rf.post('/foo/'))
|
||||||
|
self.assertEqual(response.status_code, 301)
|
||||||
|
self.assertEqual(response['Location'], '/bar/')
|
||||||
|
|
||||||
|
def test_redirect_HEAD(self):
|
||||||
|
"Default is a permanent redirect"
|
||||||
|
response = RedirectView.as_view(url='/bar/')(self.rf.head('/foo/'))
|
||||||
|
self.assertEqual(response.status_code, 301)
|
||||||
|
self.assertEqual(response['Location'], '/bar/')
|
||||||
|
|
||||||
|
def test_redirect_OPTIONS(self):
|
||||||
|
"Default is a permanent redirect"
|
||||||
|
response = RedirectView.as_view(url='/bar/')(self.rf.options('/foo/'))
|
||||||
|
self.assertEqual(response.status_code, 301)
|
||||||
|
self.assertEqual(response['Location'], '/bar/')
|
||||||
|
|
||||||
|
def test_redirect_PUT(self):
|
||||||
|
"Default is a permanent redirect"
|
||||||
|
response = RedirectView.as_view(url='/bar/')(self.rf.put('/foo/'))
|
||||||
|
self.assertEqual(response.status_code, 301)
|
||||||
|
self.assertEqual(response['Location'], '/bar/')
|
||||||
|
|
||||||
|
def test_redirect_DELETE(self):
|
||||||
|
"Default is a permanent redirect"
|
||||||
|
response = RedirectView.as_view(url='/bar/')(self.rf.delete('/foo/'))
|
||||||
|
self.assertEqual(response.status_code, 301)
|
||||||
|
self.assertEqual(response['Location'], '/bar/')
|
||||||
|
|
Loading…
Reference in New Issue