Ticket #10448: patch10448against10203withtest.diff
File patch10448against10203withtest.diff, 3.4 KB (added by , 16 years ago) |
---|
-
django/contrib/admin/options.py
782 782 'app_label': opts.app_label, 783 783 } 784 784 context.update(extra_context or {}) 785 return self.render_change_form(request, context, add=True)785 return self.render_change_form(request, context, form_url=form_url, add=True) 786 786 add_view = transaction.commit_on_success(add_view) 787 787 788 788 def change_view(self, request, object_id, extra_context=None): … … 805 805 raise Http404(_('%(name)s object with primary key %(key)r does not exist.') % {'name': force_unicode(opts.verbose_name), 'key': escape(object_id)}) 806 806 807 807 if request.method == 'POST' and request.POST.has_key("_saveasnew"): 808 return self.add_view(request, form_url='../ ../add/')808 return self.add_view(request, form_url='../add/') 809 809 810 810 ModelForm = self.get_form(request, obj) 811 811 formsets = [] -
tests/regressiontests/admin_views/tests.py
182 182 response = self.client.get('/test_admin/%s/admin_views/thing/' % self.urlbit, {'color__id__exact': 'StringNotInteger!'}) 183 183 self.assertRedirects(response, '/test_admin/%s/admin_views/thing/?e=1' % self.urlbit) 184 184 185 class SaveAsTest(TestCase): 186 fixtures = ['admin-views-users.xml','admin-views-person.xml'] 187 urlbit = 'admin' 188 189 def setUp(self): 190 self.client.login(username='super', password='secret') 191 192 def tearDown(self): 193 self.client.logout() 194 195 def testSaveAsDuplication(self): 196 """Ensure save as actually creates a new person""" 197 post_data = {'_saveasnew':'', 'name':'John M', 'gender':1} 198 response = self.client.post('/test_admin/%s/admin_views/person/1/' % self.urlbit, post_data) 199 self.assertEqual(len(Person.objects.filter(name='John M')), 1) 200 self.assertEqual(len(Person.objects.filter(id=1)),1) 201 202 def testSaveAsDisplay(self): 203 """Ensure that 'save as' is displayed when activated and after submitting invalid data aside 204 save_as_new will not show us a form to overwrite the initial model""" 205 response = self.client.get('/test_admin/%s/admin_views/person/1/' % self.urlbit) 206 self.assert_('_saveasnew' in response.content) 207 post_data = {'_saveasnew':'', 'name':'John M', 'gender':3, 'alive':'checked'} 208 response = self.client.post('/test_admin/%s/admin_views/person/1/' % self.urlbit, post_data) 209 self.assert_('_saveasnew' not in response.content) 210 self.assert_('../add/' in response.content) 211 self.assert_('Add person' in response.content) 212 185 213 class CustomModelAdminTest(AdminViewBasicTest): 186 214 urlbit = "admin2" 187 215 -
tests/regressiontests/admin_views/models.py
156 156 list_filter = ('gender',) 157 157 search_fields = ('name',) 158 158 ordering = ["id"] 159 save_as = True 159 160 160 161 class Persona(models.Model): 161 162 """