Author: russellm
Date: 2010-12-04 05:20:30 -0600 (Sat, 04 Dec 2010)
New Revision: 14808

Modified:
   django/trunk/django/views/generic/edit.py
   django/trunk/docs/ref/class-based-views.txt
   django/trunk/docs/topics/generic-views-migration.txt
   django/trunk/tests/regressiontests/generic_views/edit.py
   django/trunk/tests/regressiontests/generic_views/urls.py
Log:
Fixed #14803 -- Corrected an inconsistency in redirection handling between 
old-style generic views and class-based views. Thanks to gg for the report and 
patch.

Modified: django/trunk/django/views/generic/edit.py
===================================================================
--- django/trunk/django/views/generic/edit.py   2010-12-04 08:04:16 UTC (rev 
14807)
+++ django/trunk/django/views/generic/edit.py   2010-12-04 11:20:30 UTC (rev 
14808)
@@ -97,7 +97,7 @@
 
     def get_success_url(self):
         if self.success_url:
-            url = self.success_url
+            url = self.success_url % self.object.__dict__
         else:
             try:
                 url = self.object.get_absolute_url()

Modified: django/trunk/docs/ref/class-based-views.txt
===================================================================
--- django/trunk/docs/ref/class-based-views.txt 2010-12-04 08:04:16 UTC (rev 
14807)
+++ django/trunk/docs/ref/class-based-views.txt 2010-12-04 11:20:30 UTC (rev 
14808)
@@ -481,6 +481,11 @@
 
         The URL to redirect to when the form is successfully processed.
 
+        ``success_url`` may contain dictionary string formatting, which
+        will be interpolated against the object's field attributes. For
+        example, you could use ``success_url="/polls/%(slug)s/"`` to
+        redirect to a URL composed out of the ``slug`` field on a model.
+
     .. method:: get_form_class()
 
         Retrieve the form class to instantiate. If

Modified: django/trunk/docs/topics/generic-views-migration.txt
===================================================================
--- django/trunk/docs/topics/generic-views-migration.txt        2010-12-04 
08:04:16 UTC (rev 14807)
+++ django/trunk/docs/topics/generic-views-migration.txt        2010-12-04 
11:20:30 UTC (rev 14808)
@@ -113,6 +113,13 @@
             })
             return context
 
+``post_save_redirect`` argument to create and update views
+----------------------------------------------------------
+
+The ``post_save_redirect`` argument to the create and update views
+has been renamed ``success_url`` on the
+:class:`~django.views.generic.edit.ModelFormMixin`.
+
 ``mimetype``
 ------------
 

Modified: django/trunk/tests/regressiontests/generic_views/edit.py
===================================================================
--- django/trunk/tests/regressiontests/generic_views/edit.py    2010-12-04 
08:04:16 UTC (rev 14807)
+++ django/trunk/tests/regressiontests/generic_views/edit.py    2010-12-04 
11:20:30 UTC (rev 14808)
@@ -47,6 +47,14 @@
         self.assertRedirects(res, 'http://testserver/edit/authors/create/')
         self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall 
Munroe>'])
 
+    def test_create_with_interpolated_redirect(self):
+        res = self.client.post('/edit/authors/create/interpolate_redirect/',
+                            {'name': 'Randall Munroe', 'slug': 
'randall-munroe'})
+        self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall 
Munroe>'])
+        self.assertEqual(res.status_code, 302)
+        pk = Author.objects.all()[0].pk
+        self.assertRedirects(res, 'http://testserver/edit/author/%d/update/' % 
pk)
+
     def test_create_with_special_properties(self):
         res = self.client.get('/edit/authors/create/special/')
         self.assertEqual(res.status_code, 200)
@@ -145,6 +153,18 @@
         self.assertRedirects(res, 'http://testserver/edit/authors/create/')
         self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall 
Munroe (author of xkcd)>'])
 
+    def test_update_with_interpolated_redirect(self):
+        a = Author.objects.create(
+            name='Randall Munroe',
+            slug='randall-munroe',
+        )
+        res = self.client.post('/edit/author/%d/update/interpolate_redirect/' 
% a.pk,
+                        {'name': 'Randall Munroe (author of xkcd)', 'slug': 
'randall-munroe'})
+        self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall 
Munroe (author of xkcd)>'])
+        self.assertEqual(res.status_code, 302)
+        pk = Author.objects.all()[0].pk
+        self.assertRedirects(res, 'http://testserver/edit/author/%d/update/' % 
pk)
+
     def test_update_with_special_properties(self):
         a = Author.objects.create(
             name='Randall Munroe',

Modified: django/trunk/tests/regressiontests/generic_views/urls.py
===================================================================
--- django/trunk/tests/regressiontests/generic_views/urls.py    2010-12-04 
08:04:16 UTC (rev 14807)
+++ django/trunk/tests/regressiontests/generic_views/urls.py    2010-12-04 
11:20:30 UTC (rev 14808)
@@ -51,6 +51,8 @@
         views.NaiveAuthorCreate.as_view()),
     (r'^edit/authors/create/redirect/$',
         views.NaiveAuthorCreate.as_view(success_url='/edit/authors/create/')),
+    (r'^edit/authors/create/interpolate_redirect/$',
+        
views.NaiveAuthorCreate.as_view(success_url='/edit/author/%(id)d/update/')),
     (r'^edit/authors/create/restricted/$',
         views.AuthorCreateRestricted.as_view()),
     (r'^edit/authors/create/$',
@@ -62,6 +64,8 @@
         views.NaiveAuthorUpdate.as_view()),
     (r'^edit/author/(?P<pk>\d+)/update/redirect/$',
         views.NaiveAuthorUpdate.as_view(success_url='/edit/authors/create/')),
+    (r'^edit/author/(?P<pk>\d+)/update/interpolate_redirect/$',
+        
views.NaiveAuthorUpdate.as_view(success_url='/edit/author/%(id)d/update/')),
     (r'^edit/author/(?P<pk>\d+)/update/$',
         views.AuthorUpdate.as_view()),
     (r'^edit/author/(?P<pk>\d+)/update/special/$',
@@ -185,4 +189,4 @@
 
     # Useful for testing redirects
     (r'^accounts/login/$',  'django.contrib.auth.views.login')
-)
\ No newline at end of file
+)

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to