Merge pull request #938 from darklow/ticket_20111

Added more precise message level for succcess and warning messages
This commit is contained in:
Jannis Leidel 2013-04-08 04:56:57 -07:00
commit ed576b69f9
2 changed files with 18 additions and 13 deletions

View File

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

View File

@ -829,7 +829,7 @@ class ModelAdmin(BaseModelAdmin):
# the presence of keys in request.POST. # the presence of keys in request.POST.
if "_continue" 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 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: if post_url_continue is None:
post_url_continue = reverse('admin:%s_%s_change' % post_url_continue = reverse('admin:%s_%s_change' %
(opts.app_label, opts.model_name), (opts.app_label, opts.model_name),
@ -847,11 +847,11 @@ class ModelAdmin(BaseModelAdmin):
(escape(pk_value), escapejs(obj))) (escape(pk_value), escapejs(obj)))
elif "_addanother" in request.POST: elif "_addanother" in request.POST:
msg = _('The %(name)s "%(obj)s" was added successfully. You may add another %(name)s below.') % msg_dict 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) return HttpResponseRedirect(request.path)
else: else:
msg = _('The %(name)s "%(obj)s" was added successfully.') % msg_dict 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) return self.response_post_save_add(request, obj)
def response_change(self, request, obj): def response_change(self, request, obj):
@ -865,27 +865,27 @@ class ModelAdmin(BaseModelAdmin):
msg_dict = {'name': force_text(opts.verbose_name), 'obj': force_text(obj)} msg_dict = {'name': force_text(opts.verbose_name), 'obj': force_text(obj)}
if "_continue" in request.POST: if "_continue" in request.POST:
msg = _('The %(name)s "%(obj)s" was changed successfully. You may edit it again below.') % msg_dict 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: if "_popup" in request.REQUEST:
return HttpResponseRedirect(request.path + "?_popup=1") return HttpResponseRedirect(request.path + "?_popup=1")
else: else:
return HttpResponseRedirect(request.path) return HttpResponseRedirect(request.path)
elif "_saveasnew" in request.POST: elif "_saveasnew" in request.POST:
msg = _('The %(name)s "%(obj)s" was added successfully. You may edit it again below.') % msg_dict 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' % return HttpResponseRedirect(reverse('admin:%s_%s_change' %
(opts.app_label, opts.model_name), (opts.app_label, opts.model_name),
args=(pk_value,), args=(pk_value,),
current_app=self.admin_site.name)) current_app=self.admin_site.name))
elif "_addanother" in request.POST: elif "_addanother" in request.POST:
msg = _('The %(name)s "%(obj)s" was changed successfully. You may add another %(name)s below.') % msg_dict 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' % return HttpResponseRedirect(reverse('admin:%s_%s_add' %
(opts.app_label, opts.model_name), (opts.app_label, opts.model_name),
current_app=self.admin_site.name)) current_app=self.admin_site.name))
else: else:
msg = _('The %(name)s "%(obj)s" was changed successfully.') % msg_dict 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) return self.response_post_save_change(request, obj)
def response_post_save_add(self, request, obj): def response_post_save_add(self, request, obj):
@ -964,7 +964,7 @@ class ModelAdmin(BaseModelAdmin):
# Reminder that something needs to be selected or nothing will happen # Reminder that something needs to be selected or nothing will happen
msg = _("Items must be selected in order to perform " msg = _("Items must be selected in order to perform "
"actions on them. No items have been changed.") "actions on them. No items have been changed.")
self.message_user(request, msg) self.message_user(request, msg, messages.WARNING)
return None return None
if not select_across: if not select_across:
@ -982,7 +982,7 @@ class ModelAdmin(BaseModelAdmin):
return HttpResponseRedirect(request.get_full_path()) return HttpResponseRedirect(request.get_full_path())
else: else:
msg = _("No action selected.") msg = _("No action selected.")
self.message_user(request, msg) self.message_user(request, msg, messages.WARNING)
return None return None
@csrf_protect_m @csrf_protect_m
@ -1224,7 +1224,7 @@ class ModelAdmin(BaseModelAdmin):
else: else:
msg = _("Items must be selected in order to perform " msg = _("Items must be selected in order to perform "
"actions on them. No items have been changed.") "actions on them. No items have been changed.")
self.message_user(request, msg) self.message_user(request, msg, messages.WARNING)
action_failed = True action_failed = True
# Actions with confirmation # Actions with confirmation
@ -1269,7 +1269,7 @@ class ModelAdmin(BaseModelAdmin):
changecount) % {'count': changecount, changecount) % {'count': changecount,
'name': name, 'name': name,
'obj': force_text(obj)} 'obj': force_text(obj)}
self.message_user(request, msg) self.message_user(request, msg, messages.SUCCESS)
return HttpResponseRedirect(request.get_full_path()) return HttpResponseRedirect(request.get_full_path())
@ -1346,7 +1346,11 @@ class ModelAdmin(BaseModelAdmin):
self.log_deletion(request, obj, obj_display) self.log_deletion(request, obj, obj_display)
self.delete_model(request, obj) 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): if not self.has_change_permission(request, None):
return HttpResponseRedirect(reverse('admin:index', return HttpResponseRedirect(reverse('admin:index',