Ticket #13223: 13223.v2.diff

File 13223.v2.diff, 4.9 KB (added by kevin1024, 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:  
    342342    mattycakes@gmail.com
    343343    Glenn Maynard <glenn@zewt.org>
    344344    Jason McBrayer <http://www.carcosa.net/jason/>
     345    Kevin McCarthy <me@kevinmccarthy.org>
    345346    Kevin McConnell <kevin.mcconnell@gmail.com>
    346347    mccutchen@gmail.com
    347348    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):  
    6262
    6363    def _management_form(self):
    6464        """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):
    6666            form = ManagementForm(self.data, auto_id=self.auto_id, prefix=self.prefix)
    6767            if not form.is_valid():
    6868                raise ValidationError('ManagementForm data is missing or has been tampered with')
    class BaseFormSet(StrAndUnicode):  
    7777
    7878    def total_form_count(self):
    7979        """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):
    8181            return self.management_form.cleaned_data[TOTAL_FORM_COUNT]
    8282        else:
    8383            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):  
    191191
    192192admin.site.register(Poll, PollAdmin)
    193193admin.site.register(Novel, NovelAdmin)
     194
     195# Models for #13223
     196class Post(models.Model):
     197    title = models.CharField(max_length=200)
     198    slug = models.CharField(max_length=200, unique = True)
     199
     200class Block(models.Model):
     201    post = models.ForeignKey(Post)
     202    slug = models.CharField(max_length=200, unique = True)
     203
     204class BlockInline(admin.TabularInline):
     205    model = Block
     206
     207class PostAdmin(admin.ModelAdmin):
     208    save_as = True
     209    inlines = [BlockInline]
     210
     211admin.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  
    44
    55# local test models
    66from 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)
    89
    910
    1011class TestInline(TestCase):
    class TestInline(TestCase):  
    103104        # column cells
    104105        self.assertContains(response, '<p>Callable in QuestionInline</p>')
    105106
     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
    106147class TestInlineMedia(TestCase):
    107148    fixtures = ['admin-views-users.xml']
    108149
Back to Top