Ticket #13223: 13223.v2.diff
File 13223.v2.diff, 4.9 KB (added by , 14 years ago) |
---|
-
AUTHORS
diff --git a/AUTHORS b/AUTHORS index a32e0d6..5c794c4 100644
a b answer newbie questions, and generally made Django that much better: 342 342 mattycakes@gmail.com 343 343 Glenn Maynard <glenn@zewt.org> 344 344 Jason McBrayer <http://www.carcosa.net/jason/> 345 Kevin McCarthy <me@kevinmccarthy.org> 345 346 Kevin McConnell <kevin.mcconnell@gmail.com> 346 347 mccutchen@gmail.com 347 348 michael.mcewan@gmail.com -
django/forms/formsets.py
diff --git a/django/forms/formsets.py b/django/forms/formsets.py index 3810ebf..2dedf58 100644
a b class BaseFormSet(StrAndUnicode): 62 62 63 63 def _management_form(self): 64 64 """Returns the ManagementForm instance for this FormSet.""" 65 if self.is_bound :65 if self.is_bound and not getattr(self,'save_as_new',False): 66 66 form = ManagementForm(self.data, auto_id=self.auto_id, prefix=self.prefix) 67 67 if not form.is_valid(): 68 68 raise ValidationError('ManagementForm data is missing or has been tampered with') … … class BaseFormSet(StrAndUnicode): 77 77 78 78 def total_form_count(self): 79 79 """Returns the total number of forms in this FormSet.""" 80 if self.is_bound :80 if self.is_bound and not getattr(self,'save_as_new',False): 81 81 return self.management_form.cleaned_data[TOTAL_FORM_COUNT] 82 82 else: 83 83 initial_forms = self.initial_form_count() -
tests/regressiontests/admin_inlines/models.py
diff --git a/tests/regressiontests/admin_inlines/models.py b/tests/regressiontests/admin_inlines/models.py index ee0abd1..3101029 100644
a b class NovelAdmin(admin.ModelAdmin): 191 191 192 192 admin.site.register(Poll, PollAdmin) 193 193 admin.site.register(Novel, NovelAdmin) 194 195 # Models for #13223 196 class Post(models.Model): 197 title = models.CharField(max_length=200) 198 slug = models.CharField(max_length=200, unique = True) 199 200 class Block(models.Model): 201 post = models.ForeignKey(Post) 202 slug = models.CharField(max_length=200, unique = True) 203 204 class BlockInline(admin.TabularInline): 205 model = Block 206 207 class PostAdmin(admin.ModelAdmin): 208 save_as = True 209 inlines = [BlockInline] 210 211 admin.site.register(Post,PostAdmin) -
tests/regressiontests/admin_inlines/tests.py
diff --git a/tests/regressiontests/admin_inlines/tests.py b/tests/regressiontests/admin_inlines/tests.py index 067b3c5..2e2c8cd 100644
a b from django.test import TestCase 4 4 5 5 # local test models 6 6 from models import (Holder, Inner, InnerInline, Holder2, Inner2, Holder3, 7 Inner3, Person, OutfitItem, Fashionista, Teacher, Parent, Child) 7 Inner3, Person, OutfitItem, Fashionista, Teacher, Parent, Child, 8 Block, Post) 8 9 9 10 10 11 class TestInline(TestCase): … … class TestInline(TestCase): 103 104 # column cells 104 105 self.assertContains(response, '<p>Callable in QuestionInline</p>') 105 106 107 def test_inline_save_as(self): 108 """#13223 - ValueError with inline and save as new""" 109 p = Post.objects.create(title='test', slug='test') 110 b1 = p.block_set.create(slug='test1') 111 b2 = p.block_set.create(slug='test2') 112 b3 = p.block_set.create(slug='test3') 113 data = { 114 'block_set-TOTAL_FORMS': 6, 115 'block_set-INITIAL_FORMS': 3, 116 'block_set-MAX_NUM_FORMS': 0, 117 'block_set-0-id': b1.id, 118 'block_set-0-post': p.id, 119 'block_set-0-slug': b1.slug, 120 'block_set-1-id': b2.id, 121 'block_set-1-post': p.id, 122 'block_set-1-slug': b2.slug, 123 'block_set-2-id': b2.id, 124 'block_set-2-post': p.id, 125 'block_set-2-slug': b2.slug, 126 'block_set-3-id': '', 127 'block_set-3-post': p.id, 128 'block_set-3-slug': '', 129 'block_set-4-id': '', 130 'block_set-4-post': p.id, 131 'block_set-4-slug': '', 132 'block_set-5-id': '', 133 'block_set-5-post': p.id, 134 'block_set-5-slug': '', 135 'block_set-__prefix__-id': '', 136 'block_set-__prefix__-post': p.id, 137 'block_set-__prefix__-slug': '', 138 '_saveasnew': u'Save as new', 139 } 140 response = self.client.post('/test_admin/admin/admin_inlines/post/%s/' % p.id, data) 141 self.assertEqual(response.status_code, 200) 142 self.assertContains(response, '<input type="hidden" name="block_set-TOTAL_FORMS" value="3" id="id_block_set-TOTAL_FORMS" />') 143 self.assertContains(response, '<input type="hidden" name="block_set-INITIAL_FORMS" value="0" id="id_block_set-INITIAL_FORMS" />') 144 self.assertContains(response, '<input type="hidden" name="block_set-MAX_NUM_FORMS" id="id_block_set-MAX_NUM_FORMS" />') 145 146 106 147 class TestInlineMedia(TestCase): 107 148 fixtures = ['admin-views-users.xml'] 108 149