mirror of
https://github.com/django/django.git
synced 2025-04-01 12:06:43 +00:00
Refs #24133 -- Removed legacy formatting syntax in success_url placeholders.
Per deprecation timeline.
This commit is contained in:
parent
b6e6fcf326
commit
6eed9ae747
@ -1,5 +1,4 @@
|
|||||||
import inspect
|
import inspect
|
||||||
import re
|
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
from django.core.exceptions import ImproperlyConfigured
|
||||||
@ -13,8 +12,6 @@ from django.views.generic.detail import (
|
|||||||
BaseDetailView, SingleObjectMixin, SingleObjectTemplateResponseMixin,
|
BaseDetailView, SingleObjectMixin, SingleObjectTemplateResponseMixin,
|
||||||
)
|
)
|
||||||
|
|
||||||
PERCENT_PLACEHOLDER_REGEX = re.compile(r'%\([^\)]+\)') # RemovedInDjango110Warning
|
|
||||||
|
|
||||||
|
|
||||||
class FormMixinBase(type):
|
class FormMixinBase(type):
|
||||||
def __new__(cls, name, bases, attrs):
|
def __new__(cls, name, bases, attrs):
|
||||||
@ -173,17 +170,7 @@ class ModelFormMixin(FormMixin, SingleObjectMixin):
|
|||||||
Returns the supplied URL.
|
Returns the supplied URL.
|
||||||
"""
|
"""
|
||||||
if self.success_url:
|
if self.success_url:
|
||||||
# force_text can be removed with deprecation warning
|
url = self.success_url.format(**self.object.__dict__)
|
||||||
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__)
|
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
url = self.object.get_absolute_url()
|
url = self.object.get_absolute_url()
|
||||||
@ -308,17 +295,7 @@ class DeletionMixin(object):
|
|||||||
|
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
if self.success_url:
|
if self.success_url:
|
||||||
# force_text can be removed with deprecation warning
|
return self.success_url.format(**self.object.__dict__)
|
||||||
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__)
|
|
||||||
else:
|
else:
|
||||||
raise ImproperlyConfigured(
|
raise ImproperlyConfigured(
|
||||||
"No URL to redirect to. Provide a success_url.")
|
"No URL to redirect to. Provide a success_url.")
|
||||||
|
@ -160,12 +160,6 @@ ModelFormMixin
|
|||||||
example, you could use ``success_url="/polls/{slug}/"`` to
|
example, you could use ``success_url="/polls/{slug}/"`` to
|
||||||
redirect to a URL composed out of the ``slug`` field on a model.
|
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()
|
.. method:: get_form_class()
|
||||||
|
|
||||||
Retrieve the form class to instantiate. If
|
Retrieve the form class to instantiate. If
|
||||||
@ -259,12 +253,6 @@ DeletionMixin
|
|||||||
could use ``success_url="/parent/{parent_id}/"`` to redirect to a URL
|
could use ``success_url="/parent/{parent_id}/"`` to redirect to a URL
|
||||||
composed out of the ``parent_id`` field on a model.
|
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()
|
.. method:: get_success_url()
|
||||||
|
|
||||||
Returns the url to redirect to when the nominated object has been
|
Returns the url to redirect to when the nominated object has been
|
||||||
|
@ -5,9 +5,7 @@ import warnings
|
|||||||
from django import forms
|
from django import forms
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
from django.core.exceptions import ImproperlyConfigured
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
from django.test import (
|
from django.test import SimpleTestCase, TestCase, override_settings
|
||||||
SimpleTestCase, TestCase, ignore_warnings, override_settings,
|
|
||||||
)
|
|
||||||
from django.test.client import RequestFactory
|
from django.test.client import RequestFactory
|
||||||
from django.utils.deprecation import RemovedInDjango110Warning
|
from django.utils.deprecation import RemovedInDjango110Warning
|
||||||
from django.views.generic.base import View
|
from django.views.generic.base import View
|
||||||
@ -152,7 +150,6 @@ class CreateViewTests(TestCase):
|
|||||||
self.assertRedirects(res, '/edit/authors/create/')
|
self.assertRedirects(res, '/edit/authors/create/')
|
||||||
self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall Munroe>'])
|
self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall Munroe>'])
|
||||||
|
|
||||||
@ignore_warnings(category=RemovedInDjango110Warning)
|
|
||||||
def test_create_with_interpolated_redirect(self):
|
def test_create_with_interpolated_redirect(self):
|
||||||
res = self.client.post(
|
res = self.client.post(
|
||||||
'/edit/authors/create/interpolate_redirect/',
|
'/edit/authors/create/interpolate_redirect/',
|
||||||
@ -292,7 +289,6 @@ class UpdateViewTests(TestCase):
|
|||||||
self.assertRedirects(res, '/edit/authors/create/')
|
self.assertRedirects(res, '/edit/authors/create/')
|
||||||
self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall Munroe (author of xkcd)>'])
|
self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall Munroe (author of xkcd)>'])
|
||||||
|
|
||||||
@ignore_warnings(category=RemovedInDjango110Warning)
|
|
||||||
def test_update_with_interpolated_redirect(self):
|
def test_update_with_interpolated_redirect(self):
|
||||||
a = Author.objects.create(
|
a = Author.objects.create(
|
||||||
name='Randall Munroe',
|
name='Randall Munroe',
|
||||||
@ -399,7 +395,6 @@ class DeleteViewTests(TestCase):
|
|||||||
self.assertRedirects(res, '/edit/authors/create/')
|
self.assertRedirects(res, '/edit/authors/create/')
|
||||||
self.assertQuerysetEqual(Author.objects.all(), [])
|
self.assertQuerysetEqual(Author.objects.all(), [])
|
||||||
|
|
||||||
@ignore_warnings(category=RemovedInDjango110Warning)
|
|
||||||
def test_delete_with_interpolated_redirect(self):
|
def test_delete_with_interpolated_redirect(self):
|
||||||
a = Author.objects.create(**{'name': 'Randall Munroe', 'slug': 'randall-munroe'})
|
a = Author.objects.create(**{'name': 'Randall Munroe', 'slug': 'randall-munroe'})
|
||||||
res = self.client.post('/edit/author/%d/delete/interpolate_redirect/' % a.pk)
|
res = self.client.post('/edit/author/%d/delete/interpolate_redirect/' % a.pk)
|
||||||
|
@ -77,7 +77,7 @@ urlpatterns = [
|
|||||||
url(r'^edit/authors/create/redirect/$',
|
url(r'^edit/authors/create/redirect/$',
|
||||||
views.NaiveAuthorCreate.as_view(success_url='/edit/authors/create/')),
|
views.NaiveAuthorCreate.as_view(success_url='/edit/authors/create/')),
|
||||||
url(r'^edit/authors/create/interpolate_redirect/$',
|
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/$',
|
url(r'^edit/authors/create/interpolate_redirect_nonascii/$',
|
||||||
views.NaiveAuthorCreate.as_view(success_url='/%C3%A9dit/author/{id}/update/')),
|
views.NaiveAuthorCreate.as_view(success_url='/%C3%A9dit/author/{id}/update/')),
|
||||||
url(r'^edit/authors/create/restricted/$',
|
url(r'^edit/authors/create/restricted/$',
|
||||||
@ -92,7 +92,7 @@ urlpatterns = [
|
|||||||
url(r'^edit/author/(?P<pk>[0-9]+)/update/redirect/$',
|
url(r'^edit/author/(?P<pk>[0-9]+)/update/redirect/$',
|
||||||
views.NaiveAuthorUpdate.as_view(success_url='/edit/authors/create/')),
|
views.NaiveAuthorUpdate.as_view(success_url='/edit/authors/create/')),
|
||||||
url(r'^edit/author/(?P<pk>[0-9]+)/update/interpolate_redirect/$',
|
url(r'^edit/author/(?P<pk>[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<pk>[0-9]+)/update/interpolate_redirect_nonascii/$',
|
url(r'^edit/author/(?P<pk>[0-9]+)/update/interpolate_redirect_nonascii/$',
|
||||||
views.NaiveAuthorUpdate.as_view(success_url='/%C3%A9dit/author/{id}/update/')),
|
views.NaiveAuthorUpdate.as_view(success_url='/%C3%A9dit/author/{id}/update/')),
|
||||||
url(r'^[eé]dit/author/(?P<pk>[0-9]+)/update/$',
|
url(r'^[eé]dit/author/(?P<pk>[0-9]+)/update/$',
|
||||||
@ -106,7 +106,7 @@ urlpatterns = [
|
|||||||
url(r'^edit/author/(?P<pk>[0-9]+)/delete/redirect/$',
|
url(r'^edit/author/(?P<pk>[0-9]+)/delete/redirect/$',
|
||||||
views.NaiveAuthorDelete.as_view(success_url='/edit/authors/create/')),
|
views.NaiveAuthorDelete.as_view(success_url='/edit/authors/create/')),
|
||||||
url(r'^edit/author/(?P<pk>[0-9]+)/delete/interpolate_redirect/$',
|
url(r'^edit/author/(?P<pk>[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<pk>[0-9]+)/delete/interpolate_redirect_nonascii/$',
|
url(r'^edit/author/(?P<pk>[0-9]+)/delete/interpolate_redirect_nonascii/$',
|
||||||
views.NaiveAuthorDelete.as_view(success_url='/%C3%A9dit/authors/create/?deleted={id}')),
|
views.NaiveAuthorDelete.as_view(success_url='/%C3%A9dit/authors/create/?deleted={id}')),
|
||||||
url(r'^edit/author/(?P<pk>[0-9]+)/delete/$',
|
url(r'^edit/author/(?P<pk>[0-9]+)/delete/$',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user