Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix async messages w/ translated strings.

Change-Id: I83d2a30f94fc382d382c504ac1a7851df0c97e17
  • Loading branch information...
commit f6f2a91e14f6bdd4e1a87e31a1d6923127afee1b 1 parent c17b06d
@gabrielhurley gabrielhurley authored
Showing with 8 additions and 3 deletions.
  1. +3 −1 horizon/messages.py
  2. +5 −2 horizon/tests/message_tests.py
View
4 horizon/messages.py
@@ -21,6 +21,7 @@
from django.contrib import messages as _messages
from django.contrib.messages import constants
+from django.utils.encoding import force_unicode
def add_message(request, level, message, extra_tags='', fail_silently=False):
@@ -29,7 +30,8 @@ def add_message(request, level, message, extra_tags='', fail_silently=False):
"""
if request.is_ajax():
tag = constants.DEFAULT_TAGS[level]
- request.horizon['async_messages'].append([tag, message])
+ request.horizon['async_messages'].append([tag,
+ force_unicode(message)])
else:
return _messages.add_message(request, level, message,
extra_tags, fail_silently)
View
7 horizon/tests/message_tests.py
@@ -15,6 +15,8 @@
# under the License.
from django import http
+from django.utils.encoding import force_unicode
+from django.utils.translation import ugettext_lazy as _
from horizon import messages
from horizon import middleware
@@ -25,11 +27,12 @@
class MessageTests(test.TestCase):
def test_middleware_header(self):
req = self.request
- expected = ["error", "Giant ants are attacking San Francisco!"]
+ string = _("Giant ants are attacking San Francisco!")
+ expected = ["error", force_unicode(string)]
self.assertTrue("async_messages" in req.horizon)
self.assertItemsEqual(req.horizon['async_messages'], [])
req.META['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
- messages.error(req, expected[1])
+ messages.error(req, string)
self.assertItemsEqual(req.horizon['async_messages'], [expected])
res = http.HttpResponse()
res = middleware.HorizonMiddleware().process_response(req, res)
Please sign in to comment.
Something went wrong with that request. Please try again.