Loading django/views/generic/base.py +14 −1 Original line number Diff line number Diff line Loading @@ -173,11 +173,24 @@ class RedirectView(View): "from True to False in Django 1.9. Set an explicit value " "to silence this warning.", RemovedInDjango19Warning, stacklevel=3 stacklevel=2 ) self.permanent = True super(RedirectView, self).__init__(*args, **kwargs) @classonlymethod def as_view(cls, **initkwargs): if 'permanent' not in initkwargs and cls.permanent is _sentinel: warnings.warn( "Default value of 'RedirectView.permanent' will change " "from True to False in Django 1.9. Set an explicit value " "to silence this warning.", RemovedInDjango19Warning, stacklevel=2 ) initkwargs['permanent'] = True return super(RedirectView, cls).as_view(**initkwargs) def get_redirect_url(self, *args, **kwargs): """ Return the URL redirect to. Keyword arguments from the Loading tests/test_client/tests.py +16 −31 Original line number Diff line number Diff line Loading @@ -22,11 +22,8 @@ rather than the HTML rendered to the end-user. """ from __future__ import unicode_literals import warnings from django.core import mail from django.http import HttpResponse from django.utils.deprecation import RemovedInDjango19Warning from django.test import Client, TestCase, RequestFactory from django.test import override_settings Loading Loading @@ -177,14 +174,10 @@ class ClientTest(TestCase): def test_permanent_redirect(self): "GET a URL that redirects permanently elsewhere" with warnings.catch_warnings(): warnings.simplefilter("ignore", RemovedInDjango19Warning) response = self.client.get('/permanent_redirect_view/') # Check that the response was a 301 (permanent redirect) self.assertRedirects(response, 'http://testserver/get_view/', status_code=301) with warnings.catch_warnings(): warnings.simplefilter("ignore", RemovedInDjango19Warning) client_providing_host = Client(HTTP_HOST='django.testserver') response = client_providing_host.get('/permanent_redirect_view/') # Check that the response was a 301 (permanent redirect) with absolute URI Loading @@ -198,8 +191,6 @@ class ClientTest(TestCase): def test_redirect_to_strange_location(self): "GET a URL that redirects to a non-200 page" with warnings.catch_warnings(): warnings.simplefilter("ignore", RemovedInDjango19Warning) response = self.client.get('/double_redirect_view/') # Check that the response was a 302, and that Loading @@ -208,23 +199,17 @@ class ClientTest(TestCase): def test_follow_redirect(self): "A URL that redirects can be followed to termination." with warnings.catch_warnings(): warnings.simplefilter("ignore", RemovedInDjango19Warning) response = self.client.get('/double_redirect_view/', follow=True) self.assertRedirects(response, 'http://testserver/get_view/', status_code=302, target_status_code=200) self.assertEqual(len(response.redirect_chain), 2) def test_redirect_http(self): "GET a URL that redirects to an http URI" with warnings.catch_warnings(): warnings.simplefilter("ignore", RemovedInDjango19Warning) response = self.client.get('/http_redirect_view/', follow=True) self.assertFalse(response.test_was_secure_request) def test_redirect_https(self): "GET a URL that redirects to an https URI" with warnings.catch_warnings(): warnings.simplefilter("ignore", RemovedInDjango19Warning) response = self.client.get('/https_redirect_view/', follow=True) self.assertTrue(response.test_was_secure_request) Loading tests/test_client/urls.py +3 −3 Original line number Diff line number Diff line Loading @@ -13,10 +13,10 @@ urlpatterns = [ url(r'^raw_post_view/$', views.raw_post_view), url(r'^redirect_view/$', views.redirect_view), url(r'^secure_view/$', views.view_with_secure), url(r'^permanent_redirect_view/$', RedirectView.as_view(url='/get_view/')), url(r'^permanent_redirect_view/$', RedirectView.as_view(url='/get_view/', permanent=True)), url(r'^temporary_redirect_view/$', RedirectView.as_view(url='/get_view/', permanent=False)), url(r'^http_redirect_view/$', RedirectView.as_view(url='/secure_view/')), url(r'^https_redirect_view/$', RedirectView.as_view(url='https://testserver/secure_view/')), url(r'^http_redirect_view/$', RedirectView.as_view(url='/secure_view/', permanent=True)), url(r'^https_redirect_view/$', RedirectView.as_view(url='https://testserver/secure_view/', permanent=True)), url(r'^double_redirect_view/$', views.double_redirect_view), url(r'^bad_view/$', views.bad_view), url(r'^form_view/$', views.form_view), Loading tests/test_client_regress/urls.py +12 −12 Original line number Diff line number Diff line Loading @@ -3,7 +3,7 @@ from django.views.generic import RedirectView from . import views # TODO: Remove permanent=True where it doesn't matter in Django 1.9 urlpatterns = [ url(r'', include('test_client.urls')), Loading @@ -15,17 +15,17 @@ urlpatterns = [ url(r'^arg_view/(?P<name>.+)/$', views.view_with_argument, name='arg_view'), url(r'^nested_view/$', views.nested_view, name='nested_view'), url(r'^login_protected_redirect_view/$', views.login_protected_redirect_view), url(r'^redirects/$', RedirectView.as_view(url='/redirects/further/')), url(r'^redirects/further/$', RedirectView.as_view(url='/redirects/further/more/')), url(r'^redirects/further/more/$', RedirectView.as_view(url='/no_template_view/')), url(r'^redirect_to_non_existent_view/$', RedirectView.as_view(url='/non_existent_view/')), url(r'^redirect_to_non_existent_view2/$', RedirectView.as_view(url='/redirect_to_non_existent_view/')), url(r'^redirect_to_self/$', RedirectView.as_view(url='/redirect_to_self/')), url(r'^redirects/$', RedirectView.as_view(url='/redirects/further/', permanent=True)), url(r'^redirects/further/$', RedirectView.as_view(url='/redirects/further/more/', permanent=True)), url(r'^redirects/further/more/$', RedirectView.as_view(url='/no_template_view/', permanent=True)), url(r'^redirect_to_non_existent_view/$', RedirectView.as_view(url='/non_existent_view/', permanent=True)), url(r'^redirect_to_non_existent_view2/$', RedirectView.as_view(url='/redirect_to_non_existent_view/', permanent=True)), url(r'^redirect_to_self/$', RedirectView.as_view(url='/redirect_to_self/', permanent=True)), url(r'^redirect_to_self_with_changing_query_view/$', views.redirect_to_self_with_changing_query_view), url(r'^circular_redirect_1/$', RedirectView.as_view(url='/circular_redirect_2/')), url(r'^circular_redirect_2/$', RedirectView.as_view(url='/circular_redirect_3/')), url(r'^circular_redirect_3/$', RedirectView.as_view(url='/circular_redirect_1/')), url(r'^redirect_other_host/$', RedirectView.as_view(url='https://otherserver:8443/no_template_view/')), url(r'^circular_redirect_1/$', RedirectView.as_view(url='/circular_redirect_2/', permanent=True)), url(r'^circular_redirect_2/$', RedirectView.as_view(url='/circular_redirect_3/', permanent=True)), url(r'^circular_redirect_3/$', RedirectView.as_view(url='/circular_redirect_1/', permanent=True)), url(r'^redirect_other_host/$', RedirectView.as_view(url='https://otherserver:8443/no_template_view/', permanent=True)), url(r'^set_session/$', views.set_session_view), url(r'^check_session/$', views.check_session_view), url(r'^request_methods/$', views.request_methods_view), Loading @@ -33,7 +33,7 @@ urlpatterns = [ url(r'^check_binary/$', views.return_undecodable_binary), url(r'^parse_unicode_json/$', views.return_json_file), url(r'^check_headers/$', views.check_headers), url(r'^check_headers_redirect/$', RedirectView.as_view(url='/check_headers/')), url(r'^check_headers_redirect/$', RedirectView.as_view(url='/check_headers/', permanent=True)), url(r'^body/$', views.body), url(r'^read_all/$', views.read_all), url(r'^read_buffer/$', views.read_buffer), Loading tests/urlpatterns_reverse/reverse_lazy_urls.py +2 −1 Original line number Diff line number Diff line Loading @@ -6,5 +6,6 @@ urlpatterns = [ url(r'^redirected_to/$', empty_view, name='named-lazy-url-redirected-to'), url(r'^login/$', empty_view, name='some-login-page'), url(r'^login_required_view/$', login_required_view), url(r'^redirect/$', LazyRedirectView.as_view()), # TODO: Remove permanent=True where it doesn't matter in Django 1.9 url(r'^redirect/$', LazyRedirectView.as_view(permanent=True)), ] Loading
django/views/generic/base.py +14 −1 Original line number Diff line number Diff line Loading @@ -173,11 +173,24 @@ class RedirectView(View): "from True to False in Django 1.9. Set an explicit value " "to silence this warning.", RemovedInDjango19Warning, stacklevel=3 stacklevel=2 ) self.permanent = True super(RedirectView, self).__init__(*args, **kwargs) @classonlymethod def as_view(cls, **initkwargs): if 'permanent' not in initkwargs and cls.permanent is _sentinel: warnings.warn( "Default value of 'RedirectView.permanent' will change " "from True to False in Django 1.9. Set an explicit value " "to silence this warning.", RemovedInDjango19Warning, stacklevel=2 ) initkwargs['permanent'] = True return super(RedirectView, cls).as_view(**initkwargs) def get_redirect_url(self, *args, **kwargs): """ Return the URL redirect to. Keyword arguments from the Loading
tests/test_client/tests.py +16 −31 Original line number Diff line number Diff line Loading @@ -22,11 +22,8 @@ rather than the HTML rendered to the end-user. """ from __future__ import unicode_literals import warnings from django.core import mail from django.http import HttpResponse from django.utils.deprecation import RemovedInDjango19Warning from django.test import Client, TestCase, RequestFactory from django.test import override_settings Loading Loading @@ -177,14 +174,10 @@ class ClientTest(TestCase): def test_permanent_redirect(self): "GET a URL that redirects permanently elsewhere" with warnings.catch_warnings(): warnings.simplefilter("ignore", RemovedInDjango19Warning) response = self.client.get('/permanent_redirect_view/') # Check that the response was a 301 (permanent redirect) self.assertRedirects(response, 'http://testserver/get_view/', status_code=301) with warnings.catch_warnings(): warnings.simplefilter("ignore", RemovedInDjango19Warning) client_providing_host = Client(HTTP_HOST='django.testserver') response = client_providing_host.get('/permanent_redirect_view/') # Check that the response was a 301 (permanent redirect) with absolute URI Loading @@ -198,8 +191,6 @@ class ClientTest(TestCase): def test_redirect_to_strange_location(self): "GET a URL that redirects to a non-200 page" with warnings.catch_warnings(): warnings.simplefilter("ignore", RemovedInDjango19Warning) response = self.client.get('/double_redirect_view/') # Check that the response was a 302, and that Loading @@ -208,23 +199,17 @@ class ClientTest(TestCase): def test_follow_redirect(self): "A URL that redirects can be followed to termination." with warnings.catch_warnings(): warnings.simplefilter("ignore", RemovedInDjango19Warning) response = self.client.get('/double_redirect_view/', follow=True) self.assertRedirects(response, 'http://testserver/get_view/', status_code=302, target_status_code=200) self.assertEqual(len(response.redirect_chain), 2) def test_redirect_http(self): "GET a URL that redirects to an http URI" with warnings.catch_warnings(): warnings.simplefilter("ignore", RemovedInDjango19Warning) response = self.client.get('/http_redirect_view/', follow=True) self.assertFalse(response.test_was_secure_request) def test_redirect_https(self): "GET a URL that redirects to an https URI" with warnings.catch_warnings(): warnings.simplefilter("ignore", RemovedInDjango19Warning) response = self.client.get('/https_redirect_view/', follow=True) self.assertTrue(response.test_was_secure_request) Loading
tests/test_client/urls.py +3 −3 Original line number Diff line number Diff line Loading @@ -13,10 +13,10 @@ urlpatterns = [ url(r'^raw_post_view/$', views.raw_post_view), url(r'^redirect_view/$', views.redirect_view), url(r'^secure_view/$', views.view_with_secure), url(r'^permanent_redirect_view/$', RedirectView.as_view(url='/get_view/')), url(r'^permanent_redirect_view/$', RedirectView.as_view(url='/get_view/', permanent=True)), url(r'^temporary_redirect_view/$', RedirectView.as_view(url='/get_view/', permanent=False)), url(r'^http_redirect_view/$', RedirectView.as_view(url='/secure_view/')), url(r'^https_redirect_view/$', RedirectView.as_view(url='https://testserver/secure_view/')), url(r'^http_redirect_view/$', RedirectView.as_view(url='/secure_view/', permanent=True)), url(r'^https_redirect_view/$', RedirectView.as_view(url='https://testserver/secure_view/', permanent=True)), url(r'^double_redirect_view/$', views.double_redirect_view), url(r'^bad_view/$', views.bad_view), url(r'^form_view/$', views.form_view), Loading
tests/test_client_regress/urls.py +12 −12 Original line number Diff line number Diff line Loading @@ -3,7 +3,7 @@ from django.views.generic import RedirectView from . import views # TODO: Remove permanent=True where it doesn't matter in Django 1.9 urlpatterns = [ url(r'', include('test_client.urls')), Loading @@ -15,17 +15,17 @@ urlpatterns = [ url(r'^arg_view/(?P<name>.+)/$', views.view_with_argument, name='arg_view'), url(r'^nested_view/$', views.nested_view, name='nested_view'), url(r'^login_protected_redirect_view/$', views.login_protected_redirect_view), url(r'^redirects/$', RedirectView.as_view(url='/redirects/further/')), url(r'^redirects/further/$', RedirectView.as_view(url='/redirects/further/more/')), url(r'^redirects/further/more/$', RedirectView.as_view(url='/no_template_view/')), url(r'^redirect_to_non_existent_view/$', RedirectView.as_view(url='/non_existent_view/')), url(r'^redirect_to_non_existent_view2/$', RedirectView.as_view(url='/redirect_to_non_existent_view/')), url(r'^redirect_to_self/$', RedirectView.as_view(url='/redirect_to_self/')), url(r'^redirects/$', RedirectView.as_view(url='/redirects/further/', permanent=True)), url(r'^redirects/further/$', RedirectView.as_view(url='/redirects/further/more/', permanent=True)), url(r'^redirects/further/more/$', RedirectView.as_view(url='/no_template_view/', permanent=True)), url(r'^redirect_to_non_existent_view/$', RedirectView.as_view(url='/non_existent_view/', permanent=True)), url(r'^redirect_to_non_existent_view2/$', RedirectView.as_view(url='/redirect_to_non_existent_view/', permanent=True)), url(r'^redirect_to_self/$', RedirectView.as_view(url='/redirect_to_self/', permanent=True)), url(r'^redirect_to_self_with_changing_query_view/$', views.redirect_to_self_with_changing_query_view), url(r'^circular_redirect_1/$', RedirectView.as_view(url='/circular_redirect_2/')), url(r'^circular_redirect_2/$', RedirectView.as_view(url='/circular_redirect_3/')), url(r'^circular_redirect_3/$', RedirectView.as_view(url='/circular_redirect_1/')), url(r'^redirect_other_host/$', RedirectView.as_view(url='https://otherserver:8443/no_template_view/')), url(r'^circular_redirect_1/$', RedirectView.as_view(url='/circular_redirect_2/', permanent=True)), url(r'^circular_redirect_2/$', RedirectView.as_view(url='/circular_redirect_3/', permanent=True)), url(r'^circular_redirect_3/$', RedirectView.as_view(url='/circular_redirect_1/', permanent=True)), url(r'^redirect_other_host/$', RedirectView.as_view(url='https://otherserver:8443/no_template_view/', permanent=True)), url(r'^set_session/$', views.set_session_view), url(r'^check_session/$', views.check_session_view), url(r'^request_methods/$', views.request_methods_view), Loading @@ -33,7 +33,7 @@ urlpatterns = [ url(r'^check_binary/$', views.return_undecodable_binary), url(r'^parse_unicode_json/$', views.return_json_file), url(r'^check_headers/$', views.check_headers), url(r'^check_headers_redirect/$', RedirectView.as_view(url='/check_headers/')), url(r'^check_headers_redirect/$', RedirectView.as_view(url='/check_headers/', permanent=True)), url(r'^body/$', views.body), url(r'^read_all/$', views.read_all), url(r'^read_buffer/$', views.read_buffer), Loading
tests/urlpatterns_reverse/reverse_lazy_urls.py +2 −1 Original line number Diff line number Diff line Loading @@ -6,5 +6,6 @@ urlpatterns = [ url(r'^redirected_to/$', empty_view, name='named-lazy-url-redirected-to'), url(r'^login/$', empty_view, name='some-login-page'), url(r'^login_required_view/$', login_required_view), url(r'^redirect/$', LazyRedirectView.as_view()), # TODO: Remove permanent=True where it doesn't matter in Django 1.9 url(r'^redirect/$', LazyRedirectView.as_view(permanent=True)), ]