From 6eed9ae747a0178de817da2e56bd09e73bee84ad Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Wed, 2 Sep 2015 18:36:09 -0400 Subject: [PATCH] Refs #24133 -- Removed legacy formatting syntax in success_url placeholders. Per deprecation timeline. --- django/views/generic/edit.py | 27 ++----------------- docs/ref/class-based-views/mixins-editing.txt | 12 --------- tests/generic_views/test_edit.py | 7 +---- tests/generic_views/urls.py | 6 ++--- 4 files changed, 6 insertions(+), 46 deletions(-) diff --git a/django/views/generic/edit.py b/django/views/generic/edit.py index 9120e1dd76a..ad357117c3c 100644 --- a/django/views/generic/edit.py +++ b/django/views/generic/edit.py @@ -1,5 +1,4 @@ import inspect -import re import warnings from django.core.exceptions import ImproperlyConfigured @@ -13,8 +12,6 @@ from django.views.generic.detail import ( BaseDetailView, SingleObjectMixin, SingleObjectTemplateResponseMixin, ) -PERCENT_PLACEHOLDER_REGEX = re.compile(r'%\([^\)]+\)') # RemovedInDjango110Warning - class FormMixinBase(type): def __new__(cls, name, bases, attrs): @@ -173,17 +170,7 @@ class ModelFormMixin(FormMixin, SingleObjectMixin): Returns the supplied URL. """ if self.success_url: - # force_text can be removed with deprecation warning - self.success_url = force_text(self.success_url) - if PERCENT_PLACEHOLDER_REGEX.search(self.success_url): - warnings.warn( - "%()s placeholder style in success_url is deprecated. " - "Please replace them by the {} Python format syntax.", - RemovedInDjango110Warning, stacklevel=2 - ) - url = self.success_url % self.object.__dict__ - else: - url = self.success_url.format(**self.object.__dict__) + url = self.success_url.format(**self.object.__dict__) else: try: url = self.object.get_absolute_url() @@ -308,17 +295,7 @@ class DeletionMixin(object): def get_success_url(self): if self.success_url: - # force_text can be removed with deprecation warning - self.success_url = force_text(self.success_url) - if PERCENT_PLACEHOLDER_REGEX.search(self.success_url): - warnings.warn( - "%()s placeholder style in success_url is deprecated. " - "Please replace them by the {} Python format syntax.", - RemovedInDjango110Warning, stacklevel=2 - ) - return self.success_url % self.object.__dict__ - else: - return self.success_url.format(**self.object.__dict__) + return self.success_url.format(**self.object.__dict__) else: raise ImproperlyConfigured( "No URL to redirect to. Provide a success_url.") diff --git a/docs/ref/class-based-views/mixins-editing.txt b/docs/ref/class-based-views/mixins-editing.txt index 5456215cf1f..ed132577479 100644 --- a/docs/ref/class-based-views/mixins-editing.txt +++ b/docs/ref/class-based-views/mixins-editing.txt @@ -160,12 +160,6 @@ ModelFormMixin example, you could use ``success_url="/polls/{slug}/"`` to redirect to a URL composed out of the ``slug`` field on a model. - .. versionchanged:: 1.8 - - Support for the new brace-based Python formatting syntax has been - added. The old ``%(slug)s`` placeholder syntax support has been - deprecated and will be removed in Django 1.10. - .. method:: get_form_class() Retrieve the form class to instantiate. If @@ -259,12 +253,6 @@ DeletionMixin could use ``success_url="/parent/{parent_id}/"`` to redirect to a URL composed out of the ``parent_id`` field on a model. - .. versionchanged:: 1.8 - - Support for the new brace-based Python formatting syntax has been - added. The old ``%(slug)s`` placeholder syntax support has been - deprecated and will be removed in Django 1.10. - .. method:: get_success_url() Returns the url to redirect to when the nominated object has been diff --git a/tests/generic_views/test_edit.py b/tests/generic_views/test_edit.py index e93965a6702..669a70639d7 100644 --- a/tests/generic_views/test_edit.py +++ b/tests/generic_views/test_edit.py @@ -5,9 +5,7 @@ import warnings from django import forms from django.core.exceptions import ImproperlyConfigured from django.core.urlresolvers import reverse -from django.test import ( - SimpleTestCase, TestCase, ignore_warnings, override_settings, -) +from django.test import SimpleTestCase, TestCase, override_settings from django.test.client import RequestFactory from django.utils.deprecation import RemovedInDjango110Warning from django.views.generic.base import View @@ -152,7 +150,6 @@ class CreateViewTests(TestCase): self.assertRedirects(res, '/edit/authors/create/') self.assertQuerysetEqual(Author.objects.all(), ['']) - @ignore_warnings(category=RemovedInDjango110Warning) def test_create_with_interpolated_redirect(self): res = self.client.post( '/edit/authors/create/interpolate_redirect/', @@ -292,7 +289,6 @@ class UpdateViewTests(TestCase): self.assertRedirects(res, '/edit/authors/create/') self.assertQuerysetEqual(Author.objects.all(), ['']) - @ignore_warnings(category=RemovedInDjango110Warning) def test_update_with_interpolated_redirect(self): a = Author.objects.create( name='Randall Munroe', @@ -399,7 +395,6 @@ class DeleteViewTests(TestCase): self.assertRedirects(res, '/edit/authors/create/') self.assertQuerysetEqual(Author.objects.all(), []) - @ignore_warnings(category=RemovedInDjango110Warning) def test_delete_with_interpolated_redirect(self): a = Author.objects.create(**{'name': 'Randall Munroe', 'slug': 'randall-munroe'}) res = self.client.post('/edit/author/%d/delete/interpolate_redirect/' % a.pk) diff --git a/tests/generic_views/urls.py b/tests/generic_views/urls.py index d455924a9e3..365e23ff32d 100644 --- a/tests/generic_views/urls.py +++ b/tests/generic_views/urls.py @@ -77,7 +77,7 @@ urlpatterns = [ url(r'^edit/authors/create/redirect/$', views.NaiveAuthorCreate.as_view(success_url='/edit/authors/create/')), url(r'^edit/authors/create/interpolate_redirect/$', - views.NaiveAuthorCreate.as_view(success_url='/edit/author/%(id)d/update/')), + views.NaiveAuthorCreate.as_view(success_url='/edit/author/{id}/update/')), url(r'^edit/authors/create/interpolate_redirect_nonascii/$', views.NaiveAuthorCreate.as_view(success_url='/%C3%A9dit/author/{id}/update/')), url(r'^edit/authors/create/restricted/$', @@ -92,7 +92,7 @@ urlpatterns = [ url(r'^edit/author/(?P[0-9]+)/update/redirect/$', views.NaiveAuthorUpdate.as_view(success_url='/edit/authors/create/')), url(r'^edit/author/(?P[0-9]+)/update/interpolate_redirect/$', - views.NaiveAuthorUpdate.as_view(success_url='/edit/author/%(id)d/update/')), + views.NaiveAuthorUpdate.as_view(success_url='/edit/author/{id}/update/')), url(r'^edit/author/(?P[0-9]+)/update/interpolate_redirect_nonascii/$', views.NaiveAuthorUpdate.as_view(success_url='/%C3%A9dit/author/{id}/update/')), url(r'^[eé]dit/author/(?P[0-9]+)/update/$', @@ -106,7 +106,7 @@ urlpatterns = [ url(r'^edit/author/(?P[0-9]+)/delete/redirect/$', views.NaiveAuthorDelete.as_view(success_url='/edit/authors/create/')), url(r'^edit/author/(?P[0-9]+)/delete/interpolate_redirect/$', - views.NaiveAuthorDelete.as_view(success_url='/edit/authors/create/?deleted=%(id)s')), + views.NaiveAuthorDelete.as_view(success_url='/edit/authors/create/?deleted={id}')), url(r'^edit/author/(?P[0-9]+)/delete/interpolate_redirect_nonascii/$', views.NaiveAuthorDelete.as_view(success_url='/%C3%A9dit/authors/create/?deleted={id}')), url(r'^edit/author/(?P[0-9]+)/delete/$',