Ticket #16884: patch.diff

File patch.diff, 9.5 KB (added by Rafał Jagoda, 13 years ago)
  • tests/regressiontests/admin_views/tests.py

     
    23372337                post_data, follow=True)
    23382338        self.assertEqual(response.status_code, 200)
    23392339        # Message should contain non-ugly model name. Instance representation is set by unicode() (ugly)
    2340         self.assertContains(response, '<li class="info">The paper &quot;Paper_Deferred_author object&quot; was changed successfully.</li>', html=True)
     2340        self.assertContains(response, '<li class="success">The paper &quot;Paper_Deferred_author object&quot; was changed successfully.</li>', html=True)
    23412341
    23422342        # defer() is used in ModelAdmin.queryset()
    23432343        cl = CoverLetter.objects.create(author=u"John Doe")
     
    23522352                post_data, follow=True)
    23532353        self.assertEqual(response.status_code, 200)
    23542354        # Message should contain non-ugly model name. Instance representation is set by model's __unicode__()
    2355         self.assertContains(response, '<li class="info">The cover letter &quot;John Doe II&quot; was changed successfully.</li>', html=True)
     2355        self.assertContains(response, '<li class="success">The cover letter &quot;John Doe II&quot; was changed successfully.</li>', html=True)
    23562356
    23572357class AdminInlineFileUploadTest(TestCase):
    23582358    urls = "regressiontests.admin_views.urls"
  • django/contrib/comments/admin.py

     
    1 from django.contrib import admin
     1from django.contrib import admin, messages
    22from django.contrib.comments.models import Comment
    33from django.utils.translation import ugettext_lazy as _, ungettext
    44from django.contrib.comments import get_model
     
    6565        msg = ungettext(u'1 comment was successfully %(action)s.',
    6666                        u'%(count)s comments were successfully %(action)s.',
    6767                        n_comments)
    68         self.message_user(request, msg % {'count': n_comments, 'action': done_message(n_comments)})
     68        self.message_user(request, msg % {'count': n_comments, 'action': done_message(n_comments)}, messages.SUCCESS)
    6969
    7070# Only register the default admin if the model is the built-in comment model
    7171# (this won't be true if there's a custom comment app).
  • django/contrib/admin/options.py

     
    688688        change_message = ' '.join(change_message)
    689689        return change_message or _('No fields changed.')
    690690
    691     def message_user(self, request, message):
     691    def message_user(self, request, message, level=messages.INFO):
    692692        """
    693693        Send a message to the user. The default implementation
    694694        posts a message using the django.contrib.messages backend.
    695695        """
    696         messages.info(request, message)
     696        messages.add_message(request, level, message)
    697697
    698698    def save_form(self, request, form, change):
    699699        """
     
    773773        # Here, we distinguish between different save types by checking for
    774774        # the presence of keys in request.POST.
    775775        if "_continue" in request.POST:
    776             self.message_user(request, msg + ' ' + _("You may edit it again below."))
     776            self.message_user(request, msg + ' ' + _("You may edit it again below."), messages.SUCCESS)
    777777            if "_popup" in request.POST:
    778778                post_url_continue += "?_popup=1"
    779779            return HttpResponseRedirect(post_url_continue % pk_value)
     
    785785                # escape() calls force_unicode.
    786786                (escape(pk_value), escapejs(obj)))
    787787        elif "_addanother" in request.POST:
    788             self.message_user(request, msg + ' ' + (_("You may add another %s below.") % force_unicode(opts.verbose_name)))
     788            self.message_user(request, msg + ' ' + (_("You may add another %s below.") % force_unicode(opts.verbose_name)), messages.SUCCESS)
    789789            return HttpResponseRedirect(request.path)
    790790        else:
    791             self.message_user(request, msg)
     791            self.message_user(request, msg, messages.SUCCESS)
    792792
    793793            # Figure out where to redirect. If the user has change permission,
    794794            # redirect to the change-list page for this object. Otherwise,
     
    821821
    822822        msg = _('The %(name)s "%(obj)s" was changed successfully.') % {'name': force_unicode(verbose_name), 'obj': force_unicode(obj)}
    823823        if "_continue" in request.POST:
    824             self.message_user(request, msg + ' ' + _("You may edit it again below."))
     824            self.message_user(request, msg + ' ' + _("You may edit it again below."), messages.SUCCESS)
    825825            if "_popup" in request.REQUEST:
    826826                return HttpResponseRedirect(request.path + "?_popup=1")
    827827            else:
    828828                return HttpResponseRedirect(request.path)
    829829        elif "_saveasnew" in request.POST:
    830830            msg = _('The %(name)s "%(obj)s" was added successfully. You may edit it again below.') % {'name': force_unicode(verbose_name), 'obj': obj}
    831             self.message_user(request, msg)
     831            self.message_user(request, msg, messages.SUCCESS)
    832832            return HttpResponseRedirect(reverse('admin:%s_%s_change' %
    833833                                        (opts.app_label, module_name),
    834834                                        args=(pk_value,),
    835835                                        current_app=self.admin_site.name))
    836836        elif "_addanother" in request.POST:
    837             self.message_user(request, msg + ' ' + (_("You may add another %s below.") % force_unicode(verbose_name)))
     837            self.message_user(request, msg + ' ' + (_("You may add another %s below.") % force_unicode(verbose_name)), messages.SUCCESS)
    838838            return HttpResponseRedirect(reverse('admin:%s_%s_add' %
    839839                                        (opts.app_label, module_name),
    840840                                        current_app=self.admin_site.name))
    841841        else:
    842             self.message_user(request, msg)
     842            self.message_user(request, msg, messages.SUCCESS)
    843843            # Figure out where to redirect. If the user has change permission,
    844844            # redirect to the change-list page for this object. Otherwise,
    845845            # redirect to the admin index.
     
    898898                # Reminder that something needs to be selected or nothing will happen
    899899                msg = _("Items must be selected in order to perform "
    900900                        "actions on them. No items have been changed.")
    901                 self.message_user(request, msg)
     901                self.message_user(request, msg, messages.ERROR)
    902902                return None
    903903
    904904            if not select_across:
     
    916916                return HttpResponseRedirect(request.get_full_path())
    917917        else:
    918918            msg = _("No action selected.")
    919             self.message_user(request, msg)
     919            self.message_user(request, msg, messages.ERROR)
    920920            return None
    921921
    922922    @csrf_protect_m
     
    11581158            else:
    11591159                msg = _("Items must be selected in order to perform "
    11601160                        "actions on them. No items have been changed.")
    1161                 self.message_user(request, msg)
     1161                self.message_user(request, msg, messages.ERROR)
    11621162                action_failed = True
    11631163
    11641164        # Actions with confirmation
     
    12031203                                    changecount) % {'count': changecount,
    12041204                                                    'name': name,
    12051205                                                    'obj': force_unicode(obj)}
    1206                     self.message_user(request, msg)
     1206                    self.message_user(request, msg, messages.SUCCESS)
    12071207
    12081208                return HttpResponseRedirect(request.get_full_path())
    12091209
     
    12801280            self.log_deletion(request, obj, obj_display)
    12811281            self.delete_model(request, obj)
    12821282
    1283             self.message_user(request, _('The %(name)s "%(obj)s" was deleted successfully.') % {'name': force_unicode(opts.verbose_name), 'obj': force_unicode(obj_display)})
     1283            self.message_user(request, _('The %(name)s "%(obj)s" was deleted successfully.') % {
     1284                'name': force_unicode(opts.verbose_name),
     1285                'obj': force_unicode(obj_display)
     1286            }, messages.SUCCESS)
    12841287
    12851288            if not self.has_change_permission(request, None):
    12861289                return HttpResponseRedirect(reverse('admin:index',
  • django/contrib/admin/actions.py

     
    33"""
    44
    55from django.core.exceptions import PermissionDenied
     6from django.contrib import messages
    67from django.contrib.admin import helpers
    78from django.contrib.admin.util import get_deleted_objects, model_ngettext
    89from django.db import router
     
    4748            queryset.delete()
    4849            modeladmin.message_user(request, _("Successfully deleted %(count)d %(items)s.") % {
    4950                "count": n, "items": model_ngettext(modeladmin.opts, n)
    50             })
     51            }, messages.SUCCESS)
    5152        # Return None to display the change list page again.
    5253        return None
    5354
Back to Top