From f5c2f49eb5e27afa5fdfc40cca2ae246a0c530c7 Mon Sep 17 00:00:00 2001 From: Matjaz Gregoric Date: Wed, 9 Dec 2015 09:54:07 +0100 Subject: [PATCH] Fix issue with unicode characters in certificates. If platform name or "All rights reserved" translation contain non-ascii characters, certificate HTML view would break with "'ascii' codec can't encode character...". --- .../certificates/tests/test_webview_views.py | 10 ++++++++++ lms/djangoapps/certificates/views/webview.py | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lms/djangoapps/certificates/tests/test_webview_views.py b/lms/djangoapps/certificates/tests/test_webview_views.py index 5f16a72bae..488590f293 100644 --- a/lms/djangoapps/certificates/tests/test_webview_views.py +++ b/lms/djangoapps/certificates/tests/test_webview_views.py @@ -523,6 +523,16 @@ class CertificatesViewsTests(ModuleStoreTestCase, EventTrackingTestCase): response = self.client.get(test_url) self.assertIn('invalid', response.content) + @override_settings(FEATURES=FEATURES_WITH_CERTS_ENABLED, PLATFORM_NAME=u'Űńíćődé Űńívéŕśítӳ') + def test_render_html_view_with_unicode_platform_name(self): + test_url = get_certificate_url( + user_id=self.user.id, + course_id=unicode(self.course) + ) + self._add_course_certificates(count=1, signatory_count=0) + response = self.client.get(test_url) + self.assertEqual(response.status_code, 200) + @override_settings(FEATURES=FEATURES_WITH_CERTS_ENABLED) def test_render_html_view_with_preview_mode(self): """ diff --git a/lms/djangoapps/certificates/views/webview.py b/lms/djangoapps/certificates/views/webview.py index 592a8eb6c5..68c77d05c3 100644 --- a/lms/djangoapps/certificates/views/webview.py +++ b/lms/djangoapps/certificates/views/webview.py @@ -153,7 +153,7 @@ def _update_context_with_basic_info(context, course_id, platform_name, configura # Translators: 'All rights reserved' is a legal term used in copyrighting to protect published content reserved = _("All rights reserved") - context['copyright_text'] = '© {year} {platform_name}. {reserved}.'.format( + context['copyright_text'] = u'© {year} {platform_name}. {reserved}.'.format( year=settings.COPYRIGHT_YEAR, platform_name=platform_name, reserved=reserved