Ticket #16884: patch_2.diff

File patch_2.diff, 12.0 KB (added by H0ff1, 3 years ago)
  • django/contrib/admin/actions.py

    diff --git a/django/contrib/admin/actions.py b/django/contrib/admin/actions.py
    index 5b56402..0621406 100644
    a b Built-in, globally-available admin actions. 
    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
    def delete_selected(modeladmin, request, queryset): 
    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
  • django/contrib/admin/options.py

    diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
    index 2071792..b738b78 100644
    a b class ModelAdmin(BaseModelAdmin): 
    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        """
    class ModelAdmin(BaseModelAdmin): 
    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)
    class ModelAdmin(BaseModelAdmin): 
    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,
    class ModelAdmin(BaseModelAdmin): 
    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.
    class ModelAdmin(BaseModelAdmin): 
    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:
    class ModelAdmin(BaseModelAdmin): 
    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
    class ModelAdmin(BaseModelAdmin): 
    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
    class ModelAdmin(BaseModelAdmin): 
    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
    class ModelAdmin(BaseModelAdmin): 
    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/comments/admin.py

    diff --git a/django/contrib/admin/static/admin/img/icon_alert.gif b/django/contrib/admin/static/admin/img/icon_alert.gif
    index a1dde26..0765aa8 100644
    Binary files a/django/contrib/admin/static/admin/img/icon_alert.gif and b/django/contrib/admin/static/admin/img/icon_alert.gif differ
    diff --git a/django/contrib/comments/admin.py b/django/contrib/comments/admin.py
    index 4cb9066..e74c99c 100644
    a b  
    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
    class CommentsAdmin(admin.ModelAdmin): 
    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).
  • tests/regressiontests/admin_views/tests.py

    diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
    index 0be8b36..47858f7 100644
    a b class AdminInheritedInlinesTest(TestCase): 
    21032103        bar_id = BarAccount.objects.all()[0].id
    21042104
    21052105        # test the edit case
    2106 
    21072106        response = self.client.get('/test_admin/admin/admin_views/persona/%d/' % persona_id)
    21082107        names = name_re.findall(response.content)
    21092108        # make sure we have no duplicate HTML names
    class AdminActionsTest(TestCase): 
    23222321        }
    23232322        response = self.client.post('/test_admin/admin/admin_views/subscriber/', action_data)
    23242323        msg = """Items must be selected in order to perform actions on them. No items have been changed."""
    2325         self.assertContains(response, msg)
     2324        self.assertContains(response, '<li class="error">' + msg + '</li>', html=True)
    23262325        self.assertEqual(Subscriber.objects.count(), 2)
    23272326
    23282327    def test_user_message_on_no_action(self):
    class AdminActionsTest(TestCase): 
    23362335        }
    23372336        response = self.client.post('/test_admin/admin/admin_views/subscriber/', action_data)
    23382337        msg = """No action selected."""
    2339         self.assertContains(response, msg)
     2338        self.assertContains(response, '<li class="error">' + msg + '</li>', html=True)
    23402339        self.assertEqual(Subscriber.objects.count(), 2)
    23412340
    23422341    def test_selection_counter(self):
    class TestCustomChangeList(TestCase): 
    23772376        self.assertEqual(response.status_code, 302) # redirect somewhere
    23782377        # Hit the page once to get messages out of the queue message list
    23792378        response = self.client.get('/test_admin/%s/admin_views/gadget/' % self.urlbit)
     2379        self.assertContains(response, '<li class="success">The gadget &quot;First Gadget&quot; was added successfully.</li>', html=True)
    23802380        # Ensure that that data is still not visible on the page
    23812381        response = self.client.get('/test_admin/%s/admin_views/gadget/' % self.urlbit)
    23822382        self.assertEqual(response.status_code, 200)
    class AdminCustomQuerysetTest(TestCase): 
    24392439                post_data, follow=True)
    24402440        self.assertEqual(response.status_code, 200)
    24412441        # Message should contain non-ugly model name. Instance representation is set by unicode() (ugly)
    2442         self.assertContains(response, '<li class="info">The paper &quot;Paper_Deferred_author object&quot; was changed successfully.</li>', html=True)
     2442        self.assertContains(response, '<li class="success">The paper &quot;Paper_Deferred_author object&quot; was changed successfully.</li>', html=True)
    24432443
    24442444        # defer() is used in ModelAdmin.queryset()
    24452445        cl = CoverLetter.objects.create(author=u"John Doe")
    class AdminCustomQuerysetTest(TestCase): 
    24542454                post_data, follow=True)
    24552455        self.assertEqual(response.status_code, 200)
    24562456        # Message should contain non-ugly model name. Instance representation is set by model's __unicode__()
    2457         self.assertContains(response, '<li class="info">The cover letter &quot;John Doe II&quot; was changed successfully.</li>', html=True)
     2457        self.assertContains(response, '<li class="success">The cover letter &quot;John Doe II&quot; was changed successfully.</li>', html=True)
    24582458
    24592459class AdminInlineFileUploadTest(TestCase):
    24602460    urls = "regressiontests.admin_views.urls"
Back to Top