Code

Ticket #16884: patch_2.diff

File patch_2.diff, 12.0 KB (added by H0ff1, 2 years ago)
Line 
1diff --git a/django/contrib/admin/actions.py b/django/contrib/admin/actions.py
2index 5b56402..0621406 100644
3--- a/django/contrib/admin/actions.py
4+++ b/django/contrib/admin/actions.py
5@@ -3,6 +3,7 @@ Built-in, globally-available admin actions.
6 """
7 
8 from django.core.exceptions import PermissionDenied
9+from django.contrib import messages
10 from django.contrib.admin import helpers
11 from django.contrib.admin.util import get_deleted_objects, model_ngettext
12 from django.db import router
13@@ -47,7 +48,7 @@ def delete_selected(modeladmin, request, queryset):
14             queryset.delete()
15             modeladmin.message_user(request, _("Successfully deleted %(count)d %(items)s.") % {
16                 "count": n, "items": model_ngettext(modeladmin.opts, n)
17-            })
18+            }, messages.SUCCESS)
19         # Return None to display the change list page again.
20         return None
21 
22diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
23index 2071792..b738b78 100644
24--- a/django/contrib/admin/options.py
25+++ b/django/contrib/admin/options.py
26@@ -688,12 +688,12 @@ class ModelAdmin(BaseModelAdmin):
27         change_message = ' '.join(change_message)
28         return change_message or _('No fields changed.')
29 
30-    def message_user(self, request, message):
31+    def message_user(self, request, message, level=messages.INFO):
32         """
33         Send a message to the user. The default implementation
34         posts a message using the django.contrib.messages backend.
35         """
36-        messages.info(request, message)
37+        messages.add_message(request, level, message)
38 
39     def save_form(self, request, form, change):
40         """
41@@ -773,7 +773,7 @@ class ModelAdmin(BaseModelAdmin):
42         # Here, we distinguish between different save types by checking for
43         # the presence of keys in request.POST.
44         if "_continue" in request.POST:
45-            self.message_user(request, msg + ' ' + _("You may edit it again below."))
46+            self.message_user(request, msg + ' ' + _("You may edit it again below."), messages.SUCCESS)
47             if "_popup" in request.POST:
48                 post_url_continue += "?_popup=1"
49             return HttpResponseRedirect(post_url_continue % pk_value)
50@@ -785,10 +785,10 @@ class ModelAdmin(BaseModelAdmin):
51                 # escape() calls force_unicode.
52                 (escape(pk_value), escapejs(obj)))
53         elif "_addanother" in request.POST:
54-            self.message_user(request, msg + ' ' + (_("You may add another %s below.") % force_unicode(opts.verbose_name)))
55+            self.message_user(request, msg + ' ' + (_("You may add another %s below.") % force_unicode(opts.verbose_name)), messages.SUCCESS)
56             return HttpResponseRedirect(request.path)
57         else:
58-            self.message_user(request, msg)
59+            self.message_user(request, msg, messages.SUCCESS)
60 
61             # Figure out where to redirect. If the user has change permission,
62             # redirect to the change-list page for this object. Otherwise,
63@@ -821,25 +821,25 @@ class ModelAdmin(BaseModelAdmin):
64 
65         msg = _('The %(name)s "%(obj)s" was changed successfully.') % {'name': force_unicode(verbose_name), 'obj': force_unicode(obj)}
66         if "_continue" in request.POST:
67-            self.message_user(request, msg + ' ' + _("You may edit it again below."))
68+            self.message_user(request, msg + ' ' + _("You may edit it again below."), messages.SUCCESS)
69             if "_popup" in request.REQUEST:
70                 return HttpResponseRedirect(request.path + "?_popup=1")
71             else:
72                 return HttpResponseRedirect(request.path)
73         elif "_saveasnew" in request.POST:
74             msg = _('The %(name)s "%(obj)s" was added successfully. You may edit it again below.') % {'name': force_unicode(verbose_name), 'obj': obj}
75-            self.message_user(request, msg)
76+            self.message_user(request, msg, messages.SUCCESS)
77             return HttpResponseRedirect(reverse('admin:%s_%s_change' %
78                                         (opts.app_label, module_name),
79                                         args=(pk_value,),
80                                         current_app=self.admin_site.name))
81         elif "_addanother" in request.POST:
82-            self.message_user(request, msg + ' ' + (_("You may add another %s below.") % force_unicode(verbose_name)))
83+            self.message_user(request, msg + ' ' + (_("You may add another %s below.") % force_unicode(verbose_name)), messages.SUCCESS)
84             return HttpResponseRedirect(reverse('admin:%s_%s_add' %
85                                         (opts.app_label, module_name),
86                                         current_app=self.admin_site.name))
87         else:
88-            self.message_user(request, msg)
89+            self.message_user(request, msg, messages.SUCCESS)
90             # Figure out where to redirect. If the user has change permission,
91             # redirect to the change-list page for this object. Otherwise,
92             # redirect to the admin index.
93@@ -898,7 +898,7 @@ class ModelAdmin(BaseModelAdmin):
94                 # Reminder that something needs to be selected or nothing will happen
95                 msg = _("Items must be selected in order to perform "
96                         "actions on them. No items have been changed.")
97-                self.message_user(request, msg)
98+                self.message_user(request, msg, messages.ERROR)
99                 return None
100 
101             if not select_across:
102@@ -916,7 +916,7 @@ class ModelAdmin(BaseModelAdmin):
103                 return HttpResponseRedirect(request.get_full_path())
104         else:
105             msg = _("No action selected.")
106-            self.message_user(request, msg)
107+            self.message_user(request, msg, messages.ERROR)
108             return None
109 
110     @csrf_protect_m
111@@ -1158,7 +1158,7 @@ class ModelAdmin(BaseModelAdmin):
112             else:
113                 msg = _("Items must be selected in order to perform "
114                         "actions on them. No items have been changed.")
115-                self.message_user(request, msg)
116+                self.message_user(request, msg, messages.ERROR)
117                 action_failed = True
118 
119         # Actions with confirmation
120@@ -1203,7 +1203,7 @@ class ModelAdmin(BaseModelAdmin):
121                                     changecount) % {'count': changecount,
122                                                     'name': name,
123                                                     'obj': force_unicode(obj)}
124-                    self.message_user(request, msg)
125+                    self.message_user(request, msg, messages.SUCCESS)
126 
127                 return HttpResponseRedirect(request.get_full_path())
128 
129@@ -1280,7 +1280,10 @@ class ModelAdmin(BaseModelAdmin):
130             self.log_deletion(request, obj, obj_display)
131             self.delete_model(request, obj)
132 
133-            self.message_user(request, _('The %(name)s "%(obj)s" was deleted successfully.') % {'name': force_unicode(opts.verbose_name), 'obj': force_unicode(obj_display)})
134+            self.message_user(request, _('The %(name)s "%(obj)s" was deleted successfully.') % {
135+                'name': force_unicode(opts.verbose_name),
136+                'obj': force_unicode(obj_display)
137+            }, messages.SUCCESS)
138 
139             if not self.has_change_permission(request, None):
140                 return HttpResponseRedirect(reverse('admin:index',
141diff --git a/django/contrib/admin/static/admin/img/icon_alert.gif b/django/contrib/admin/static/admin/img/icon_alert.gif
142index a1dde26..0765aa8 100644
143Binary files a/django/contrib/admin/static/admin/img/icon_alert.gif and b/django/contrib/admin/static/admin/img/icon_alert.gif differ
144diff --git a/django/contrib/comments/admin.py b/django/contrib/comments/admin.py
145index 4cb9066..e74c99c 100644
146--- a/django/contrib/comments/admin.py
147+++ b/django/contrib/comments/admin.py
148@@ -1,4 +1,4 @@
149-from django.contrib import admin
150+from django.contrib import admin, messages
151 from django.contrib.comments.models import Comment
152 from django.utils.translation import ugettext_lazy as _, ungettext
153 from django.contrib.comments import get_model
154@@ -65,7 +65,7 @@ class CommentsAdmin(admin.ModelAdmin):
155         msg = ungettext(u'1 comment was successfully %(action)s.',
156                         u'%(count)s comments were successfully %(action)s.',
157                         n_comments)
158-        self.message_user(request, msg % {'count': n_comments, 'action': done_message(n_comments)})
159+        self.message_user(request, msg % {'count': n_comments, 'action': done_message(n_comments)}, messages.SUCCESS)
160 
161 # Only register the default admin if the model is the built-in comment model
162 # (this won't be true if there's a custom comment app).
163diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
164index 0be8b36..47858f7 100644
165--- a/tests/regressiontests/admin_views/tests.py
166+++ b/tests/regressiontests/admin_views/tests.py
167@@ -2103,7 +2103,6 @@ class AdminInheritedInlinesTest(TestCase):
168         bar_id = BarAccount.objects.all()[0].id
169 
170         # test the edit case
171-
172         response = self.client.get('/test_admin/admin/admin_views/persona/%d/' % persona_id)
173         names = name_re.findall(response.content)
174         # make sure we have no duplicate HTML names
175@@ -2322,7 +2321,7 @@ class AdminActionsTest(TestCase):
176         }
177         response = self.client.post('/test_admin/admin/admin_views/subscriber/', action_data)
178         msg = """Items must be selected in order to perform actions on them. No items have been changed."""
179-        self.assertContains(response, msg)
180+        self.assertContains(response, '<li class="error">' + msg + '</li>', html=True)
181         self.assertEqual(Subscriber.objects.count(), 2)
182 
183     def test_user_message_on_no_action(self):
184@@ -2336,7 +2335,7 @@ class AdminActionsTest(TestCase):
185         }
186         response = self.client.post('/test_admin/admin/admin_views/subscriber/', action_data)
187         msg = """No action selected."""
188-        self.assertContains(response, msg)
189+        self.assertContains(response, '<li class="error">' + msg + '</li>', html=True)
190         self.assertEqual(Subscriber.objects.count(), 2)
191 
192     def test_selection_counter(self):
193@@ -2377,6 +2376,7 @@ class TestCustomChangeList(TestCase):
194         self.assertEqual(response.status_code, 302) # redirect somewhere
195         # Hit the page once to get messages out of the queue message list
196         response = self.client.get('/test_admin/%s/admin_views/gadget/' % self.urlbit)
197+        self.assertContains(response, '<li class="success">The gadget &quot;First Gadget&quot; was added successfully.</li>', html=True)
198         # Ensure that that data is still not visible on the page
199         response = self.client.get('/test_admin/%s/admin_views/gadget/' % self.urlbit)
200         self.assertEqual(response.status_code, 200)
201@@ -2439,7 +2439,7 @@ class AdminCustomQuerysetTest(TestCase):
202                 post_data, follow=True)
203         self.assertEqual(response.status_code, 200)
204         # Message should contain non-ugly model name. Instance representation is set by unicode() (ugly)
205-        self.assertContains(response, '<li class="info">The paper &quot;Paper_Deferred_author object&quot; was changed successfully.</li>', html=True)
206+        self.assertContains(response, '<li class="success">The paper &quot;Paper_Deferred_author object&quot; was changed successfully.</li>', html=True)
207 
208         # defer() is used in ModelAdmin.queryset()
209         cl = CoverLetter.objects.create(author=u"John Doe")
210@@ -2454,7 +2454,7 @@ class AdminCustomQuerysetTest(TestCase):
211                 post_data, follow=True)
212         self.assertEqual(response.status_code, 200)
213         # Message should contain non-ugly model name. Instance representation is set by model's __unicode__()
214-        self.assertContains(response, '<li class="info">The cover letter &quot;John Doe II&quot; was changed successfully.</li>', html=True)
215+        self.assertContains(response, '<li class="success">The cover letter &quot;John Doe II&quot; was changed successfully.</li>', html=True)
216 
217 class AdminInlineFileUploadTest(TestCase):
218     urls = "regressiontests.admin_views.urls"