Ticket #10640: add_form.diff

File add_form.diff, 4.9 KB (added by j.c.sackett, 15 years ago)

Updated patch including missing template for tests and updated documentation.

  • django/contrib/admin/options.py

     
    585585            'save_on_top': self.save_on_top,
    586586            'root_path': self.admin_site.root_path,
    587587        })
     588        if add:
     589            admin_form_template = getattr(self, 'add_form_template', None)
     590        else:
     591            admin_form_template = getattr(self, 'change_form_template', None)
    588592        context_instance = template.RequestContext(request, current_app=self.admin_site.name)
    589         return render_to_response(self.change_form_template or [
     593        return render_to_response(admin_form_template or [
    590594            "admin/%s/%s/change_form.html" % (app_label, opts.object_name.lower()),
    591595            "admin/%s/change_form.html" % app_label,
    592596            "admin/change_form.html"
  • tests/regressiontests/admin_views/tests.py

     
    541541        self.failUnlessEqual(request.status_code, 200)
    542542        self.assert_("var hello = 'Hello!';" in request.content)
    543543        self.assertTemplateUsed(request, 'custom_admin/change_list.html')
    544 
    545         # Test custom change form template
     544       
     545        # Test custom add form template
    546546        request = self.client.get('/test_admin/admin/admin_views/customarticle/add/')
    547         self.assertTemplateUsed(request, 'custom_admin/change_form.html')
    548 
    549         # Add an article so we can test delete and history views
     547        self.assertTemplateUsed(request, 'custom_admin/add_form.html')
     548       
     549        # Add an article so we can test delete, change, and history views
    550550        post = self.client.post('/test_admin/admin/admin_views/customarticle/add/', {
    551551            'content': '<p>great article</p>',
    552552            'date_0': '2008-03-18',
     
    555555        self.assertRedirects(post, '/test_admin/admin/admin_views/customarticle/')
    556556        self.failUnlessEqual(CustomArticle.objects.all().count(), 1)
    557557
    558         # Test custom delete and object history templates
     558        # Test custom delete, change, and object history templates
     559        # Test custom change form template
     560        request = self.client.get('/test_admin/admin/admin_views/customarticle/1/')
     561        self.assertTemplateUsed(request, 'custom_admin/change_form.html')
    559562        request = self.client.get('/test_admin/admin/admin_views/customarticle/1/delete/')
    560563        self.assertTemplateUsed(request, 'custom_admin/delete_confirmation.html')
    561564        request = self.client.get('/test_admin/admin/admin_views/customarticle/1/history/')
  • tests/regressiontests/admin_views/models.py

     
    106106    """
    107107    change_list_template = 'custom_admin/change_list.html'
    108108    change_form_template = 'custom_admin/change_form.html'
     109    add_form_template = 'custom_admin/add_form.html'
    109110    object_history_template = 'custom_admin/object_history.html'
    110111    delete_confirmation_template = 'custom_admin/delete_confirmation.html'
    111112
  • tests/templates/custom_admin/add_form.html

     
     1{% extends "admin/change_form.html" %}
  • docs/ref/contrib/admin/index.txt

     
    681681If you don't specify this attribute, a default template shipped with Django
    682682that provides the standard appearance is used.
    683683
     684.. attribute:: ModelAdmin.add_form_template
     685
     686Path to a custom template that will be used by the model object creation
     687views. Templates can override or extend base admin templates as described in
     688`Overriding Admin Template`_.
     689
     690If you don't specify this attribute, a default template shipped with Django
     691that provides the standard appearance is used.
     692
    684693.. attribute:: ModelAdmin.change_form_template
    685694
    686 Path to a custom template that will be used by both the model object creation
    687 and change views. Templates can override or extend base admin templates as
    688 described in `Overriding Admin Templates`_.
     695Path to a custom template that will be used by the model object change views.
     696Templates can override or extend base admin templates as described in
     697`Overriding Admin Templates`_.
    689698
    690699If you don't specify this attribute, a default template shipped with Django
    691700that provides the standard appearance is used.
Back to Top