Skip to content

Commit

Permalink
Fix async messages w/ translated strings.
Browse files Browse the repository at this point in the history
Change-Id: I83d2a30f94fc382d382c504ac1a7851df0c97e17
  • Loading branch information
gabrielhurley committed Jun 14, 2012
1 parent c17b06d commit f6f2a91
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 3 additions & 1 deletion horizon/messages.py
Expand Up @@ -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):
Expand All @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions horizon/tests/message_tests.py
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit f6f2a91

Please sign in to comment.