Skip to content

Commit

Permalink
Fix #20111 Added more precise message level for succcess and warning …
Browse files Browse the repository at this point in the history
…messages
  • Loading branch information
darklow committed Apr 8, 2013
1 parent f9ab543 commit 3be368c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
3 changes: 2 additions & 1 deletion django/contrib/admin/actions.py
Expand Up @@ -3,6 +3,7 @@
"""

from django.core.exceptions import PermissionDenied
from django.contrib import messages
from django.contrib.admin import helpers
from django.contrib.admin.util import get_deleted_objects, model_ngettext
from django.db import router
Expand Down Expand Up @@ -47,7 +48,7 @@ def delete_selected(modeladmin, request, queryset):
queryset.delete()
modeladmin.message_user(request, _("Successfully deleted %(count)d %(items)s.") % {
"count": n, "items": model_ngettext(modeladmin.opts, n)
})
}, messages.SUCCESS)
# Return None to display the change list page again.
return None

Expand Down
28 changes: 16 additions & 12 deletions django/contrib/admin/options.py
Expand Up @@ -829,7 +829,7 @@ def response_add(self, request, obj, post_url_continue=None):
# the presence of keys in request.POST.
if "_continue" in request.POST:
msg = _('The %(name)s "%(obj)s" was added successfully. You may edit it again below.') % msg_dict
self.message_user(request, msg)
self.message_user(request, msg, messages.SUCCESS)
if post_url_continue is None:
post_url_continue = reverse('admin:%s_%s_change' %
(opts.app_label, opts.model_name),
Expand All @@ -847,11 +847,11 @@ def response_add(self, request, obj, post_url_continue=None):
(escape(pk_value), escapejs(obj)))
elif "_addanother" in request.POST:
msg = _('The %(name)s "%(obj)s" was added successfully. You may add another %(name)s below.') % msg_dict
self.message_user(request, msg)
self.message_user(request, msg, messages.SUCCESS)
return HttpResponseRedirect(request.path)
else:
msg = _('The %(name)s "%(obj)s" was added successfully.') % msg_dict
self.message_user(request, msg)
self.message_user(request, msg, messages.SUCCESS)
return self.response_post_save_add(request, obj)

def response_change(self, request, obj):
Expand All @@ -865,27 +865,27 @@ def response_change(self, request, obj):
msg_dict = {'name': force_text(opts.verbose_name), 'obj': force_text(obj)}
if "_continue" in request.POST:
msg = _('The %(name)s "%(obj)s" was changed successfully. You may edit it again below.') % msg_dict
self.message_user(request, msg)
self.message_user(request, msg, messages.SUCCESS)
if "_popup" in request.REQUEST:
return HttpResponseRedirect(request.path + "?_popup=1")
else:
return HttpResponseRedirect(request.path)
elif "_saveasnew" in request.POST:
msg = _('The %(name)s "%(obj)s" was added successfully. You may edit it again below.') % msg_dict
self.message_user(request, msg)
self.message_user(request, msg, messages.SUCCESS)
return HttpResponseRedirect(reverse('admin:%s_%s_change' %
(opts.app_label, opts.model_name),
args=(pk_value,),
current_app=self.admin_site.name))
elif "_addanother" in request.POST:
msg = _('The %(name)s "%(obj)s" was changed successfully. You may add another %(name)s below.') % msg_dict
self.message_user(request, msg)
self.message_user(request, msg, messages.SUCCESS)
return HttpResponseRedirect(reverse('admin:%s_%s_add' %
(opts.app_label, opts.model_name),
current_app=self.admin_site.name))
else:
msg = _('The %(name)s "%(obj)s" was changed successfully.') % msg_dict
self.message_user(request, msg)
self.message_user(request, msg, messages.SUCCESS)
return self.response_post_save_change(request, obj)

def response_post_save_add(self, request, obj):
Expand Down Expand Up @@ -964,7 +964,7 @@ def response_action(self, request, queryset):
# Reminder that something needs to be selected or nothing will happen
msg = _("Items must be selected in order to perform "
"actions on them. No items have been changed.")
self.message_user(request, msg)
self.message_user(request, msg, messages.WARNING)
return None

if not select_across:
Expand All @@ -982,7 +982,7 @@ def response_action(self, request, queryset):
return HttpResponseRedirect(request.get_full_path())
else:
msg = _("No action selected.")
self.message_user(request, msg)
self.message_user(request, msg, messages.WARNING)
return None

@csrf_protect_m
Expand Down Expand Up @@ -1224,7 +1224,7 @@ def changelist_view(self, request, extra_context=None):
else:
msg = _("Items must be selected in order to perform "
"actions on them. No items have been changed.")
self.message_user(request, msg)
self.message_user(request, msg, messages.WARNING)
action_failed = True

# Actions with confirmation
Expand Down Expand Up @@ -1269,7 +1269,7 @@ def changelist_view(self, request, extra_context=None):
changecount) % {'count': changecount,
'name': name,
'obj': force_text(obj)}
self.message_user(request, msg)
self.message_user(request, msg, messages.SUCCESS)

return HttpResponseRedirect(request.get_full_path())

Expand Down Expand Up @@ -1346,7 +1346,11 @@ def delete_view(self, request, object_id, extra_context=None):
self.log_deletion(request, obj, obj_display)
self.delete_model(request, obj)

self.message_user(request, _('The %(name)s "%(obj)s" was deleted successfully.') % {'name': force_text(opts.verbose_name), 'obj': force_text(obj_display)})
self.message_user(request, _(
'The %(name)s "%(obj)s" was deleted successfully.') % {
'name': force_text(opts.verbose_name),
'obj': force_text(obj_display)},
messages.SUCCESS)

if not self.has_change_permission(request, None):
return HttpResponseRedirect(reverse('admin:index',
Expand Down

2 comments on commit 3be368c

@bmispelon
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit broke the admin_views tests: http://dpaste.org/XZY4h/

It should be easy to fix by using the right class on lines like these: https://github.com/django/django/blob/master/tests/admin_views/tests.py#L2631

@bmispelon
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's a PR that fix the tests: #1003

Please sign in to comment.