Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
r12216 - in django/trunk: django/contrib/admin docs/ref/contrib/admin tests/regressiontests/admin_vi ews tests/templates/custom_admin
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  1 message - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
nore...@djangoproject.com  
View profile  
 More options Jan 12 2010, 6:34 pm
From: nore...@djangoproject.com
Date: Tue, 12 Jan 2010 17:34:03 -0600 (CST)
Local: Tues, Jan 12 2010 6:34 pm
Subject: [Changeset] r12216 - in django/trunk: django/contrib/admin docs/ref/contrib/admin tests/regressiontests/admin_views tests/templates/custom_admin
Author: jezdez
Date: 2010-01-12 17:34:03 -0600 (Tue, 12 Jan 2010)
New Revision: 12216

Added:
   django/trunk/tests/templates/custom_admin/add_form.html
Modified:
   django/trunk/django/contrib/admin/options.py
   django/trunk/docs/ref/contrib/admin/index.txt
   django/trunk/tests/regressiontests/admin_views/models.py
   django/trunk/tests/regressiontests/admin_views/tests.py
Log:
Fixed #10640 - Adds a add_form_template option to ModelAdmin. Thanks jcsackett.

Modified: django/trunk/django/contrib/admin/options.py
===================================================================
--- django/trunk/django/contrib/admin/options.py        2010-01-12 22:03:00 UTC (rev 12215)
+++ django/trunk/django/contrib/admin/options.py        2010-01-12 23:34:03 UTC (rev 12216)
@@ -200,6 +200,7 @@
     inlines = []

     # Custom templates (designed to be over-ridden in subclasses)
+    add_form_template = None
     change_form_template = None
     change_list_template = None
     delete_confirmation_template = None
@@ -618,8 +619,12 @@
             'save_on_top': self.save_on_top,
             'root_path': self.admin_site.root_path,
         })
+        if add and self.add_form_template is not None:
+            form_template = self.add_form_template
+        else:
+            form_template = self.change_form_template
         context_instance = template.RequestContext(request, current_app=self.admin_site.name)
-        return render_to_response(self.change_form_template or [
+        return render_to_response(form_template or [
             "admin/%s/%s/change_form.html" % (app_label, opts.object_name.lower()),
             "admin/%s/change_form.html" % app_label,
             "admin/change_form.html"

Modified: django/trunk/docs/ref/contrib/admin/index.txt
===================================================================
--- django/trunk/docs/ref/contrib/admin/index.txt       2010-01-12 22:03:00 UTC (rev 12215)
+++ django/trunk/docs/ref/contrib/admin/index.txt       2010-01-12 23:34:03 UTC (rev 12216)
@@ -712,11 +712,20 @@
 If you don't specify this attribute, a default template shipped with Django
 that provides the standard appearance is used.

+.. attribute:: ModelAdmin.add_form_template
+
+Path to a custom template that will be used by the model object creation
+views. Templates can override or extend base admin templates as described in
+`Overriding Admin Templates`_.
+
+If you don't specify this attribute, a default template shipped with Django
+that provides the standard appearance is used.
+
 .. attribute:: ModelAdmin.change_form_template

-Path to a custom template that will be used by both the model object creation
-and change views. Templates can override or extend base admin templates as
-described in `Overriding Admin Templates`_.
+Path to a custom template that will be used by the model object change views.
+Templates can override or extend base admin templates as described in
+`Overriding Admin Templates`_.

 If you don't specify this attribute, a default template shipped with Django
 that provides the standard appearance is used.

Modified: django/trunk/tests/regressiontests/admin_views/models.py
===================================================================
--- django/trunk/tests/regressiontests/admin_views/models.py    2010-01-12 22:03:00 UTC (rev 12215)
+++ django/trunk/tests/regressiontests/admin_views/models.py    2010-01-12 23:34:03 UTC (rev 12216)
@@ -110,6 +110,7 @@
     """
     change_list_template = 'custom_admin/change_list.html'
     change_form_template = 'custom_admin/change_form.html'
+    add_form_template = 'custom_admin/add_form.html'
     object_history_template = 'custom_admin/object_history.html'
     delete_confirmation_template = 'custom_admin/delete_confirmation.html'

Modified: django/trunk/tests/regressiontests/admin_views/tests.py
===================================================================
--- django/trunk/tests/regressiontests/admin_views/tests.py     2010-01-12 22:03:00 UTC (rev 12215)
+++ django/trunk/tests/regressiontests/admin_views/tests.py     2010-01-12 23:34:03 UTC (rev 12216)
@@ -550,11 +550,11 @@
         self.assert_("var hello = 'Hello!';" in request.content)
         self.assertTemplateUsed(request, 'custom_admin/change_list.html')

-        # Test custom change form template
+        # Test custom add form template
         request = self.client.get('/test_admin/admin/admin_views/customarticle/add/')
-        self.assertTemplateUsed(request, 'custom_admin/change_form.html')
+        self.assertTemplateUsed(request, 'custom_admin/add_form.html')

-        # Add an article so we can test delete and history views
+        # Add an article so we can test delete, change, and history views
         post = self.client.post('/test_admin/admin/admin_views/customarticle/add/', {
             'content': '<p>great article</p>',
             'date_0': '2008-03-18',
@@ -563,7 +563,10 @@
         self.assertRedirects(post, '/test_admin/admin/admin_views/customarticle/')
         self.failUnlessEqual(CustomArticle.objects.all().count(), 1)

-        # Test custom delete and object history templates
+        # Test custom delete, change, and object history templates
+        # Test custom change form template
+        request = self.client.get('/test_admin/admin/admin_views/customarticle/1/')
+        self.assertTemplateUsed(request, 'custom_admin/change_form.html')
         request = self.client.get('/test_admin/admin/admin_views/customarticle/1/delete/')
         self.assertTemplateUsed(request, 'custom_admin/delete_confirmation.html')
         request = self.client.get('/test_admin/admin/admin_views/customarticle/1/history/')

Added: django/trunk/tests/templates/custom_admin/add_form.html
===================================================================
--- django/trunk/tests/templates/custom_admin/add_form.html                             (rev 0)
+++ django/trunk/tests/templates/custom_admin/add_form.html     2010-01-12 23:34:03 UTC (rev 12216)
@@ -0,0 +1 @@
+{% extends "admin/change_form.html" %}


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »