From 4fa2c259785920e75100ec88ac194a31ddb3467c Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Sat, 16 Nov 2013 08:36:08 +0100 Subject: [PATCH] Make sure QuestionView.get_question_message is in a unicode context. This is important if the attribute question_message is set with ugettext_lazy which needs an unicode context Fixes #1066 --- openslides/utils/views.py | 19 ++++++++----------- tests/utils/test_views.py | 6 ++++++ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/openslides/utils/views.py b/openslides/utils/views.py index b920def75..402eb7696 100644 --- a/openslides/utils/views.py +++ b/openslides/utils/views.py @@ -355,7 +355,7 @@ class QuestionView(RedirectView): """ Returns the question. """ - return self.question_message + return unicode(self.question_message) def get_answer_options(self): """ @@ -376,16 +376,13 @@ class QuestionView(RedirectView): for option in self.get_answer_options()]) messages.warning( self.request, - """ - %(message)s -
- - %(option_fields)s -
- """ % {'message': self.get_question_message(), - 'url': self.request.path, - 'csrf': csrf(self.request)['csrf_token'], - 'option_fields': option_fields}) + '%(message)s
' + '' + '%(option_fields)s
' % { + 'message': self.get_question_message(), + 'url': self.request.path, + 'csrf': csrf(self.request)['csrf_token'], + 'option_fields': option_fields}) def pre_post_redirect(self, request, *args, **kwargs): """ diff --git a/tests/utils/test_views.py b/tests/utils/test_views.py index 78b97f03f..c7f271263 100644 --- a/tests/utils/test_views.py +++ b/tests/utils/test_views.py @@ -164,6 +164,9 @@ class QuestionViewTest(ViewTestCase): view.question_message = 'new_question' self.assertEqual(get_question_message(), 'new_question') + # Make sure it is unicode, so ugettext_lazy can work + self.assertIsInstance(get_question_message(), unicode) + def test_get_answer_options(self): view = views.QuestionView() get_answer_options = view.get_answer_options @@ -186,6 +189,9 @@ class QuestionViewTest(ViewTestCase): self.assertTrue(mock_messages.warning.called) + question = mock_messages.warning.call_args[0][1] + self.assertIn('the question', question) + def set_context(sender, request, context, **kwargs): """