Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #938 from darklow/ticket_20111

Added more precise message level for succcess and warning messages
  • Loading branch information...
commit ed576b69f9cc0202adbb82da778f1ff6036626b4 2 parents b5c0b3d + 3be368c
@jezdez jezdez authored
Showing with 18 additions and 13 deletions.
  1. +2 −1  django/contrib/admin/actions.py
  2. +16 −12 django/contrib/admin/options.py
View
3  django/contrib/admin/actions.py
@@ -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
@@ -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
View
28 django/contrib/admin/options.py
@@ -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),
@@ -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):
@@ -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):
@@ -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:
@@ -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
@@ -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
@@ -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())
@@ -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',
Please sign in to comment.
Something went wrong with that request. Please try again.