Ticket #19044: 0001-Fixed-19044-Made-DeletionMixin-interpolate-it-s-suce.patch

File 0001-Fixed-19044-Made-DeletionMixin-interpolate-it-s-suce.patch, 4.6 KB (added by Simon Charette, 12 years ago)
  • django/views/generic/edit.py

    From f76eeb6b45cf822ffab7019cd152a54ccf641657 Mon Sep 17 00:00:00 2001
    From: Simon Charette <charette.s@gmail.com>
    Date: Tue, 5 Feb 2013 01:40:43 -0500
    Subject: [PATCH] Fixed #19044 -- Made `DeletionMixin` interpolate it's
     `sucess_url`.
    
    Thanks to nxvl and slurms for the initial patch and ptone for the review.
    ---
     django/views/generic/edit.py                |    5 +++--
     docs/releases/1.6.txt                       |    4 ++++
     tests/regressiontests/generic_views/edit.py |   19 +++++++++++++------
     tests/regressiontests/generic_views/urls.py |    2 ++
     4 files changed, 22 insertions(+), 8 deletions(-)
    
    diff --git a/django/views/generic/edit.py b/django/views/generic/edit.py
    index 97a6c0a..5b97fc8 100644
    a b class DeletionMixin(object):  
    242242        redirects to the success URL.
    243243        """
    244244        self.object = self.get_object()
     245        success_url = self.get_success_url()
    245246        self.object.delete()
    246         return HttpResponseRedirect(self.get_success_url())
     247        return HttpResponseRedirect(success_url)
    247248
    248249    # Add support for browsers which only accept GET and POST for now.
    249250    def post(self, *args, **kwargs):
    class DeletionMixin(object):  
    251252
    252253    def get_success_url(self):
    253254        if self.success_url:
    254             return self.success_url
     255            return self.success_url % self.object.__dict__
    255256        else:
    256257            raise ImproperlyConfigured(
    257258                "No URL to redirect to. Provide a success_url.")
  • docs/releases/1.6.txt

    diff --git a/docs/releases/1.6.txt b/docs/releases/1.6.txt
    index 32e5172..dc78a94 100644
    a b Minor features  
    6161  :attr:`~django.core.management.BaseCommand.leave_locale_alone` internal
    6262  option. See :ref:`management-commands-and-locales` for more details.
    6363
     64* :class:`~django.views.generic.edit.DeletionMixin` with a defined
     65  :attr:`~django.views.generic.edit.DeletionMixin.success_url` now consistently
     66  interpolate it with its object's ``__dict__`` before proceeding to deletion.
     67
    6468Backwards incompatible changes in 1.6
    6569=====================================
    6670
  • tests/regressiontests/generic_views/edit.py

    diff --git a/tests/regressiontests/generic_views/edit.py b/tests/regressiontests/generic_views/edit.py
    index 0f1eb3c..3bacc31 100644
    a b from .models import Artist, Author  
    1313
    1414
    1515class FormMixinTests(TestCase):
    16      def test_initial_data(self):
    17          """ Test instance independence of initial data dict (see #16138) """
    18          initial_1 = FormMixin().get_initial()
    19          initial_1['foo'] = 'bar'
    20          initial_2 = FormMixin().get_initial()
    21          self.assertNotEqual(initial_1, initial_2)
     16    def test_initial_data(self):
     17        """ Test instance independence of initial data dict (see #16138) """
     18        initial_1 = FormMixin().get_initial()
     19        initial_1['foo'] = 'bar'
     20        initial_2 = FormMixin().get_initial()
     21        self.assertNotEqual(initial_1, initial_2)
    2222
    2323
    2424class BasicFormTests(TestCase):
    class DeleteViewTests(TestCase):  
    283283        self.assertRedirects(res, 'http://testserver/edit/authors/create/')
    284284        self.assertQuerysetEqual(Author.objects.all(), [])
    285285
     286    def test_delete_with_interpolated_redirect(self):
     287        a = Author.objects.create(**{'name': 'Randall Munroe', 'slug': 'randall-munroe'})
     288        res = self.client.post('/edit/author/%d/delete/interpolate_redirect/' % a.pk)
     289        self.assertEqual(res.status_code, 302)
     290        self.assertRedirects(res, 'http://testserver/edit/authors/create/?deleted=%d' % a.pk)
     291        self.assertQuerysetEqual(Author.objects.all(), [])
     292
    286293    def test_delete_with_special_properties(self):
    287294        a = Author.objects.create(**{'name': 'Randall Munroe', 'slug': 'randall-munroe'})
    288295        res = self.client.get('/edit/author/%d/delete/special/' % a.pk)
  • tests/regressiontests/generic_views/urls.py

    diff --git a/tests/regressiontests/generic_views/urls.py b/tests/regressiontests/generic_views/urls.py
    index 5730905..695b502 100644
    a b urlpatterns = patterns('',  
    9797        views.NaiveAuthorDelete.as_view()),
    9898    (r'^edit/author/(?P<pk>\d+)/delete/redirect/$',
    9999        views.NaiveAuthorDelete.as_view(success_url='/edit/authors/create/')),
     100    (r'^edit/author/(?P<pk>\d+)/delete/interpolate_redirect/$',
     101        views.NaiveAuthorDelete.as_view(success_url='/edit/authors/create/?deleted=%(id)s')),
    100102    (r'^edit/author/(?P<pk>\d+)/delete/$',
    101103        views.AuthorDelete.as_view()),
    102104    (r'^edit/author/(?P<pk>\d+)/delete/special/$',
Back to Top