From c421a4fd92990fa830f2f645df044b0f0f1fc32a Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Mon, 5 Apr 2010 12:02:27 +0000 Subject: [PATCH] Fixed #11949 -- Added a hook to allow ModelAdmin customization of the delete selected template. Thanks to bendavis78 for the report and patch, and Ramiro Morales for his cleanup work. git-svn-id: http://code.djangoproject.com/svn/django/trunk@12916 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/admin/actions.py | 2 +- django/contrib/admin/options.py | 1 + docs/ref/contrib/admin/index.txt | 9 +++++++++ tests/regressiontests/admin_views/models.py | 1 + tests/regressiontests/admin_views/tests.py | 6 ++++++ .../custom_admin/delete_selected_confirmation.html | 1 + 6 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 tests/templates/custom_admin/delete_selected_confirmation.html diff --git a/django/contrib/admin/actions.py b/django/contrib/admin/actions.py index 5cc2f811e490b..69374626cc097 100644 --- a/django/contrib/admin/actions.py +++ b/django/contrib/admin/actions.py @@ -68,7 +68,7 @@ def delete_selected(modeladmin, request, queryset): } # Display the confirmation page - return render_to_response(modeladmin.delete_confirmation_template or [ + return render_to_response(modeladmin.delete_selected_confirmation_template or [ "admin/%s/%s/delete_selected_confirmation.html" % (app_label, opts.object_name.lower()), "admin/%s/delete_selected_confirmation.html" % app_label, "admin/delete_selected_confirmation.html" diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py index 7d2904002ea81..6f66893c2629d 100644 --- a/django/contrib/admin/options.py +++ b/django/contrib/admin/options.py @@ -206,6 +206,7 @@ class ModelAdmin(BaseModelAdmin): change_form_template = None change_list_template = None delete_confirmation_template = None + delete_selected_confirmation_template = None object_history_template = None # Actions diff --git a/docs/ref/contrib/admin/index.txt b/docs/ref/contrib/admin/index.txt index e80af72f46770..c779b3ca6dc65 100644 --- a/docs/ref/contrib/admin/index.txt +++ b/docs/ref/contrib/admin/index.txt @@ -737,6 +737,15 @@ templates used by the :class:`ModelAdmin` views: Path to a custom template, used by :meth:`delete_view` for displaying a confirmation page when deleting one or more objects. +.. attribute:: ModelAdmin.delete_selected_confirmation_template + + .. versionadded:: 1.2 + + Path to a custom template, used by the :meth:`delete_selected` + action method for displaying a confirmation page when deleting one + or more objects. See the :ref:`actions + documentation`. + .. attribute:: ModelAdmin.object_history_template Path to a custom template, used by :meth:`history_view`. diff --git a/tests/regressiontests/admin_views/models.py b/tests/regressiontests/admin_views/models.py index e66e65fa854a2..be5782886fdf6 100644 --- a/tests/regressiontests/admin_views/models.py +++ b/tests/regressiontests/admin_views/models.py @@ -119,6 +119,7 @@ class CustomArticleAdmin(admin.ModelAdmin): add_form_template = 'custom_admin/add_form.html' object_history_template = 'custom_admin/object_history.html' delete_confirmation_template = 'custom_admin/delete_confirmation.html' + delete_selected_confirmation_template = 'custom_admin/delete_selected_confirmation.html' def changelist_view(self, request): "Test that extra_context works" diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py index 3414ea06469fb..00c5db4dfb00f 100644 --- a/tests/regressiontests/admin_views/tests.py +++ b/tests/regressiontests/admin_views/tests.py @@ -606,6 +606,12 @@ def testCustomModelAdminTemplates(self): 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.post('/test_admin/admin/admin_views/customarticle/', data={ + 'index': 0, + 'action': ['delete_selected'], + '_selected_action': ['1'], + }) + self.assertTemplateUsed(request, 'custom_admin/delete_selected_confirmation.html') request = self.client.get('/test_admin/admin/admin_views/customarticle/1/history/') self.assertTemplateUsed(request, 'custom_admin/object_history.html') diff --git a/tests/templates/custom_admin/delete_selected_confirmation.html b/tests/templates/custom_admin/delete_selected_confirmation.html new file mode 100644 index 0000000000000..9268536092403 --- /dev/null +++ b/tests/templates/custom_admin/delete_selected_confirmation.html @@ -0,0 +1 @@ +{% extends "admin/delete_selected_confirmation.html" %}