Ticket #14803: 14803.2.diff
File 14803.2.diff, 4.9 KB (added by , 14 years ago) |
---|
-
django/views/generic/edit.py
97 97 98 98 def get_success_url(self): 99 99 if self.success_url: 100 url = self.success_url 100 url = self.success_url % self.object.__dict__ 101 101 else: 102 102 try: 103 103 url = self.object.get_absolute_url() -
tests/regressiontests/generic_views/edit.py
47 47 self.assertRedirects(res, 'http://testserver/edit/authors/create/') 48 48 self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall Munroe>']) 49 49 50 def test_create_with_interpolated_redirect(self): 51 res = self.client.post('/edit/authors/create/interpolate_redirect/', 52 {'name': 'Randall Munroe', 'slug': 'randall-munroe'}) 53 self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall Munroe>']) 54 self.assertEqual(res.status_code, 302) 55 pk = Author.objects.all()[0].pk 56 self.assertRedirects(res, 'http://testserver/edit/author/%d/update/'%pk) 57 50 58 def test_create_with_special_properties(self): 51 59 res = self.client.get('/edit/authors/create/special/') 52 60 self.assertEqual(res.status_code, 200) … … 145 153 self.assertRedirects(res, 'http://testserver/edit/authors/create/') 146 154 self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall Munroe (author of xkcd)>']) 147 155 156 def test_update_with_interpolated_redirect(self): 157 a = Author.objects.create( 158 name='Randall Munroe', 159 slug='randall-munroe', 160 ) 161 res = self.client.post('/edit/author/%d/update/interpolate_redirect/' % a.pk, 162 {'name': 'Randall Munroe (author of xkcd)', 'slug': 'randall-munroe'}) 163 self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall Munroe (author of xkcd)>']) 164 self.assertEqual(res.status_code, 302) 165 pk = Author.objects.all()[0].pk 166 self.assertRedirects(res, 'http://testserver/edit/author/%d/update/'%pk) 167 148 168 def test_update_with_special_properties(self): 149 169 a = Author.objects.create( 150 170 name='Randall Munroe', -
tests/regressiontests/generic_views/urls.py
51 51 views.NaiveAuthorCreate.as_view()), 52 52 (r'^edit/authors/create/redirect/$', 53 53 views.NaiveAuthorCreate.as_view(success_url='/edit/authors/create/')), 54 (r'^edit/authors/create/interpolate_redirect/$', 55 views.NaiveAuthorCreate.as_view(success_url='/edit/author/%(id)d/update/')), 54 56 (r'^edit/authors/create/restricted/$', 55 57 views.AuthorCreateRestricted.as_view()), 56 58 (r'^edit/authors/create/$', … … 62 64 views.NaiveAuthorUpdate.as_view()), 63 65 (r'^edit/author/(?P<pk>\d+)/update/redirect/$', 64 66 views.NaiveAuthorUpdate.as_view(success_url='/edit/authors/create/')), 67 (r'^edit/author/(?P<pk>\d+)/update/interpolate_redirect/$', 68 views.NaiveAuthorUpdate.as_view(success_url='/edit/author/%(id)d/update/')), 65 69 (r'^edit/author/(?P<pk>\d+)/update/$', 66 70 views.AuthorUpdate.as_view()), 67 71 (r'^edit/author/(?P<pk>\d+)/update/special/$', … … 185 189 186 190 # Useful for testing redirects 187 191 (r'^accounts/login/$', 'django.contrib.auth.views.login') 188 ) 189 No newline at end of file 192 ) -
docs/topics/generic-views-migration.txt
113 113 }) 114 114 return context 115 115 116 ``post_save_redirect`` argument to create and update views 117 ---------------------------------------------------------- 118 119 The ``post_save_redirect`` argument to the create and update views 120 has been renamed ``context_object_name`` on the 121 :class:`~django.views.generic.edit.ModelFormMixin`. 122 116 123 ``mimetype`` 117 124 ------------ 118 125 -
docs/ref/class-based-views.txt
481 481 482 482 The URL to redirect to when the form is successfully processed. 483 483 484 ``success_url`` may contain dictionary string formatting, which 485 will be interpolated against the object's field attributes. For 486 example, you could use ``success_url="/polls/%(slug)s/"``. 487 484 488 .. method:: get_form_class() 485 489 486 490 Retrieve the form class to instantiate. If