Ticket #13223: 13223.templatefix.diff

File 13223.templatefix.diff, 5.0 KB (added by Preston Timmons, 14 years ago)

Patch that modifies add_view to maintain the _saveasnew parameter

  • 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/contrib/admin/options.py

    diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
    index c603210..8c3604f 100644
    a b class ModelAdmin(BaseModelAdmin):  
    942942            'errors': helpers.AdminErrorList(form, formsets),
    943943            'root_path': self.admin_site.root_path,
    944944            'app_label': opts.app_label,
     945            'saveasnew': "_saveasnew" in request.POST,
    945946        }
    946947        context.update(extra_context or {})
    947948        return self.render_change_form(request, context, form_url=form_url, add=True)
  • django/contrib/admin/templates/admin/change_form.html

    diff --git a/django/contrib/admin/templates/admin/change_form.html b/django/contrib/admin/templates/admin/change_form.html
    index b32f76d..088e458 100644
    a b  
    6363
    6464{% submit_row %}
    6565
     66{% if saveasnew %}<input type="hidden" value="_saveasnew" name="_saveasnew">{% endif %}
     67
    6668{% if adminform and add %}
    6769   <script type="text/javascript">document.getElementById("{{ adminform.first_field.id_for_label }}").focus();</script>
    6870{% endif %}
  • 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..73b1990 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        """
     109        #13223 - ValueError with inline and save as new.
     110        Verifies that _saveasnew is included in the form when it is
     111        rendered due to validation errors.
     112        """
     113
     114        p = Post.objects.create(title='test', slug='test')
     115        b1 = p.block_set.create(slug='test1')
     116        b2 = p.block_set.create(slug='test2')
     117        b3 = p.block_set.create(slug='test3')
     118
     119        data = {
     120            'block_set-TOTAL_FORMS': 6,
     121            'block_set-INITIAL_FORMS': 3,
     122            'block_set-MAX_NUM_FORMS': 0,
     123            'block_set-0-id': b1.id,
     124            'block_set-0-post': p.id,
     125            'block_set-0-slug': b1.slug,
     126            'block_set-1-id': b2.id,
     127            'block_set-1-post': p.id,
     128            'block_set-1-slug': b2.slug,
     129            'block_set-2-id': b2.id,
     130            'block_set-2-post': p.id,
     131            'block_set-2-slug': b2.slug,
     132            'block_set-3-id': '',
     133            'block_set-3-post': p.id,
     134            'block_set-3-slug': '',
     135            'block_set-4-id': '',
     136            'block_set-4-post': p.id,
     137            'block_set-4-slug': '',
     138            'block_set-5-id': '',
     139            'block_set-5-post': p.id,
     140            'block_set-5-slug': '',
     141            'block_set-__prefix__-id': '',
     142            'block_set-__prefix__-post': p.id,
     143            'block_set-__prefix__-slug': '',
     144            '_saveasnew': u'Save as new',
     145        }
     146        response = self.client.post('/test_admin/admin/admin_inlines/post/%s/' % p.id, data)
     147        self.assertEqual(response.status_code, 200)
     148        self.assertEqual(response.context['inline_admin_formset'].formset.errors[0]['slug'],
     149            [u'Block with this Slug already exists.'])
     150        self.assertContains(response, '<input type="hidden" value="_saveasnew" name="_saveasnew">')
     151
     152
     153
    106154class TestInlineMedia(TestCase):
    107155    fixtures = ['admin-views-users.xml']
    108156
Back to Top