From 53dac996efedf9138938ad4aa5647cb68006937c Mon Sep 17 00:00:00 2001 From: Carl Meyer Date: Thu, 20 Jan 2011 01:00:47 +0000 Subject: [PATCH] Poured a little more perfectionism into the delete-confirmation templates. git-svn-id: http://code.djangoproject.com/svn/django/trunk@15250 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/admin/actions.py | 14 ++++++++++++-- django/contrib/admin/options.py | 11 +++++++++-- .../admin/templates/admin/delete_confirmation.html | 2 +- .../admin/delete_selected_confirmation.html | 6 +++--- tests/regressiontests/admin_views/tests.py | 2 +- 5 files changed, 26 insertions(+), 9 deletions(-) diff --git a/django/contrib/admin/actions.py b/django/contrib/admin/actions.py index 6e52e34d94..c68184a768 100644 --- a/django/contrib/admin/actions.py +++ b/django/contrib/admin/actions.py @@ -52,9 +52,19 @@ def delete_selected(modeladmin, request, queryset): # Return None to display the change list page again. return None + if len(queryset) == 1: + objects_name = force_unicode(opts.verbose_name) + else: + objects_name = force_unicode(opts.verbose_name_plural) + + if perms_needed or protected: + title = _("Cannot delete %(name)s") % {"name": objects_name} + else: + title = _("Are you sure?") + context = { - "title": _("Are you sure?"), - "object_name": force_unicode(opts.verbose_name), + "title": title, + "objects_name": objects_name, "deletable_objects": [deletable_objects], 'queryset': queryset, "perms_lacking": perms_needed, diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py index f51070ca67..4ad21eb42b 100644 --- a/django/contrib/admin/options.py +++ b/django/contrib/admin/options.py @@ -1193,9 +1193,16 @@ class ModelAdmin(BaseModelAdmin): return HttpResponseRedirect("../../../../") return HttpResponseRedirect("../../") + object_name = force_unicode(opts.verbose_name) + + if perms_needed or protected: + title = _("Cannot delete %(name)s") % {"name": object_name} + else: + title = _("Are you sure?") + context = { - "title": _("Are you sure?"), - "object_name": force_unicode(opts.verbose_name), + "title": title, + "object_name": object_name, "object": obj, "deleted_objects": deleted_objects, "perms_lacking": perms_needed, diff --git a/django/contrib/admin/templates/admin/delete_confirmation.html b/django/contrib/admin/templates/admin/delete_confirmation.html index db4ef627b7..0e6d47e68d 100644 --- a/django/contrib/admin/templates/admin/delete_confirmation.html +++ b/django/contrib/admin/templates/admin/delete_confirmation.html @@ -22,7 +22,7 @@ {% endif %} {% if protected %} -

{% blocktrans with object as escaped_object %}Deleting the {{ object_name }} '{{ escaped_object }}' is not possible, because it would require deleting the following protected related objects:{% endblocktrans %}

+

{% blocktrans with object as escaped_object %}Deleting the {{ object_name }} '{{ escaped_object }}' would require deleting the following protected related objects:{% endblocktrans %}