Code

Ticket #10640: add_form.diff

File add_form.diff, 4.9 KB (added by jcsackett, 4 years ago)

Updated patch including missing template for tests and updated documentation.

Line 
1Index: django/contrib/admin/options.py
2===================================================================
3--- django/contrib/admin/options.py     (revision 11866)
4+++ django/contrib/admin/options.py     (working copy)
5@@ -585,8 +585,12 @@
6             'save_on_top': self.save_on_top,
7             'root_path': self.admin_site.root_path,
8         })
9+        if add:
10+            admin_form_template = getattr(self, 'add_form_template', None)
11+        else:
12+            admin_form_template = getattr(self, 'change_form_template', None)
13         context_instance = template.RequestContext(request, current_app=self.admin_site.name)
14-        return render_to_response(self.change_form_template or [
15+        return render_to_response(admin_form_template or [
16             "admin/%s/%s/change_form.html" % (app_label, opts.object_name.lower()),
17             "admin/%s/change_form.html" % app_label,
18             "admin/change_form.html"
19Index: tests/regressiontests/admin_views/tests.py
20===================================================================
21--- tests/regressiontests/admin_views/tests.py  (revision 11866)
22+++ tests/regressiontests/admin_views/tests.py  (working copy)
23@@ -541,12 +541,12 @@
24         self.failUnlessEqual(request.status_code, 200)
25         self.assert_("var hello = 'Hello!';" in request.content)
26         self.assertTemplateUsed(request, 'custom_admin/change_list.html')
27-
28-        # Test custom change form template
29+       
30+        # Test custom add form template
31         request = self.client.get('/test_admin/admin/admin_views/customarticle/add/')
32-        self.assertTemplateUsed(request, 'custom_admin/change_form.html')
33-
34-        # Add an article so we can test delete and history views
35+        self.assertTemplateUsed(request, 'custom_admin/add_form.html')
36+       
37+        # Add an article so we can test delete, change, and history views
38         post = self.client.post('/test_admin/admin/admin_views/customarticle/add/', {
39             'content': '<p>great article</p>',
40             'date_0': '2008-03-18',
41@@ -555,7 +555,10 @@
42         self.assertRedirects(post, '/test_admin/admin/admin_views/customarticle/')
43         self.failUnlessEqual(CustomArticle.objects.all().count(), 1)
44 
45-        # Test custom delete and object history templates
46+        # Test custom delete, change, and object history templates
47+        # Test custom change form template
48+        request = self.client.get('/test_admin/admin/admin_views/customarticle/1/')
49+        self.assertTemplateUsed(request, 'custom_admin/change_form.html')
50         request = self.client.get('/test_admin/admin/admin_views/customarticle/1/delete/')
51         self.assertTemplateUsed(request, 'custom_admin/delete_confirmation.html')
52         request = self.client.get('/test_admin/admin/admin_views/customarticle/1/history/')
53Index: tests/regressiontests/admin_views/models.py
54===================================================================
55--- tests/regressiontests/admin_views/models.py (revision 11866)
56+++ tests/regressiontests/admin_views/models.py (working copy)
57@@ -106,6 +106,7 @@
58     """
59     change_list_template = 'custom_admin/change_list.html'
60     change_form_template = 'custom_admin/change_form.html'
61+    add_form_template = 'custom_admin/add_form.html'
62     object_history_template = 'custom_admin/object_history.html'
63     delete_confirmation_template = 'custom_admin/delete_confirmation.html'
64 
65Index: tests/templates/custom_admin/add_form.html
66===================================================================
67--- tests/templates/custom_admin/add_form.html  (revision 0)
68+++ tests/templates/custom_admin/add_form.html  (revision 0)
69@@ -0,0 +1 @@
70+{% extends "admin/change_form.html" %}
71Index: docs/ref/contrib/admin/index.txt
72===================================================================
73--- docs/ref/contrib/admin/index.txt    (revision 11866)
74+++ docs/ref/contrib/admin/index.txt    (working copy)
75@@ -681,11 +681,20 @@
76 If you don't specify this attribute, a default template shipped with Django
77 that provides the standard appearance is used.
78 
79+.. attribute:: ModelAdmin.add_form_template
80+
81+Path to a custom template that will be used by the model object creation
82+views. Templates can override or extend base admin templates as described in
83+`Overriding Admin Template`_.
84+
85+If you don't specify this attribute, a default template shipped with Django
86+that provides the standard appearance is used.
87+
88 .. attribute:: ModelAdmin.change_form_template
89 
90-Path to a custom template that will be used by both the model object creation
91-and change views. Templates can override or extend base admin templates as
92-described in `Overriding Admin Templates`_.
93+Path to a custom template that will be used by the model object change views.
94+Templates can override or extend base admin templates as described in
95+`Overriding Admin Templates`_.
96 
97 If you don't specify this attribute, a default template shipped with Django
98 that provides the standard appearance is used.