Skip to content

Commit

Permalink
Fixed #11949 -- Added a hook to allow ModelAdmin customization of the…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
freakboy3742 committed Apr 5, 2010
1 parent 4e4deca commit c421a4f
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion django/contrib/admin/actions.py
Expand Up @@ -68,7 +68,7 @@ def delete_selected(modeladmin, request, queryset):
} }


# Display the confirmation page # 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/%s/delete_selected_confirmation.html" % (app_label, opts.object_name.lower()),
"admin/%s/delete_selected_confirmation.html" % app_label, "admin/%s/delete_selected_confirmation.html" % app_label,
"admin/delete_selected_confirmation.html" "admin/delete_selected_confirmation.html"
Expand Down
1 change: 1 addition & 0 deletions django/contrib/admin/options.py
Expand Up @@ -206,6 +206,7 @@ class ModelAdmin(BaseModelAdmin):
change_form_template = None change_form_template = None
change_list_template = None change_list_template = None
delete_confirmation_template = None delete_confirmation_template = None
delete_selected_confirmation_template = None
object_history_template = None object_history_template = None


# Actions # Actions
Expand Down
9 changes: 9 additions & 0 deletions docs/ref/contrib/admin/index.txt
Expand Up @@ -737,6 +737,15 @@ templates used by the :class:`ModelAdmin` views:
Path to a custom template, used by :meth:`delete_view` for displaying a Path to a custom template, used by :meth:`delete_view` for displaying a
confirmation page when deleting one or more objects. 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<ref-contrib-admin-actions>`.

.. attribute:: ModelAdmin.object_history_template .. attribute:: ModelAdmin.object_history_template


Path to a custom template, used by :meth:`history_view`. Path to a custom template, used by :meth:`history_view`.
Expand Down
1 change: 1 addition & 0 deletions tests/regressiontests/admin_views/models.py
Expand Up @@ -119,6 +119,7 @@ class CustomArticleAdmin(admin.ModelAdmin):
add_form_template = 'custom_admin/add_form.html' add_form_template = 'custom_admin/add_form.html'
object_history_template = 'custom_admin/object_history.html' object_history_template = 'custom_admin/object_history.html'
delete_confirmation_template = 'custom_admin/delete_confirmation.html' delete_confirmation_template = 'custom_admin/delete_confirmation.html'
delete_selected_confirmation_template = 'custom_admin/delete_selected_confirmation.html'


def changelist_view(self, request): def changelist_view(self, request):
"Test that extra_context works" "Test that extra_context works"
Expand Down
6 changes: 6 additions & 0 deletions tests/regressiontests/admin_views/tests.py
Expand Up @@ -606,6 +606,12 @@ def testCustomModelAdminTemplates(self):
self.assertTemplateUsed(request, 'custom_admin/change_form.html') self.assertTemplateUsed(request, 'custom_admin/change_form.html')
request = self.client.get('/test_admin/admin/admin_views/customarticle/1/delete/') request = self.client.get('/test_admin/admin/admin_views/customarticle/1/delete/')
self.assertTemplateUsed(request, 'custom_admin/delete_confirmation.html') 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/') request = self.client.get('/test_admin/admin/admin_views/customarticle/1/history/')
self.assertTemplateUsed(request, 'custom_admin/object_history.html') self.assertTemplateUsed(request, 'custom_admin/object_history.html')


Expand Down
@@ -0,0 +1 @@
{% extends "admin/delete_selected_confirmation.html" %}

0 comments on commit c421a4f

Please sign in to comment.