% if last_accessed_courseware_url:
diff --git a/lms/templates/enrollment/course_enrollment_message.html b/lms/templates/enrollment/course_enrollment_message.html
index 9351e05a33..e37a192f0f 100644
--- a/lms/templates/enrollment/course_enrollment_message.html
+++ b/lms/templates/enrollment/course_enrollment_message.html
@@ -1,4 +1,4 @@
-<%! from openedx.core.djangolib.markup import ugettext as _ %>
+<%! from django.utils.translation import ugettext as _ %>
<%page expression_filter="h"/>
% for course_msg in course_enrollment_messages:
diff --git a/openedx/core/djangolib/markup.py b/openedx/core/djangolib/markup.py
index fb935f9099..1037ae2d20 100644
--- a/openedx/core/djangolib/markup.py
+++ b/openedx/core/djangolib/markup.py
@@ -2,48 +2,31 @@
Utilities for use in Mako markup.
"""
-from django.utils.translation import ugettext as django_ugettext
-from django.utils.translation import ungettext as django_ungettext
import markupsafe
-# So that we can use escape() imported from here.
-escape = markupsafe.escape # pylint: disable=invalid-name
-
-
-def ugettext(text):
- """Translate a string, and escape it as plain text.
-
- Use like this in Mako::
-
- <% from openedx.core.djangolib.markup import ugettext as _ %>
-
${_("Hello, world!")}
-
- Or with formatting::
-
- <% from openedx.core.djangolib.markup import HTML, ugettext as _ %>
- ${_("Write & send {start}email{end}").format(
- start=HTML("
"),
- end=HTML(""),
- )}
-
- """
- return markupsafe.escape(django_ugettext(text))
-
-
-def ungettext(text1, text2, num):
- """Translate a number-sensitive string, and escape it as plain text."""
- return markupsafe.escape(django_ungettext(text1, text2, num))
+# Text() can be used to declare a string as plain text, as HTML() is used
+# for HTML. It simply wraps markupsafe's escape, which will HTML-escape if
+# it isn't already escaped.
+Text = markupsafe.escape # pylint: disable=invalid-name
def HTML(html): # pylint: disable=invalid-name
- """Mark a string as already HTML, so that it won't be escaped before output.
+ """
+ Mark a string as already HTML, so that it won't be escaped before output.
- Use this when formatting HTML into other strings::
+ Use this function when formatting HTML into other strings. It must be
+ used in conjunction with ``Text()``, and both ``HTML()`` and ``Text()``
+ must be closed before any calls to ``format()``::
- <% from openedx.core.djangolib.markup import HTML, ugettext as _ %>
- ${_("Write & send {start}email{end}").format(
- start=HTML("
"),
+ <%page expression_filter="h"/>
+ <%!
+ from django.utils.translation import ugettext as _
+
+ from openedx.core.djangolib.markup import Text, HTML
+ %>
+ ${Text(_("Write & send {start}email{end}")).format(
+ start=HTML("".format(user.email),
end=HTML(""),
)}
diff --git a/openedx/core/djangolib/tests/test_markup.py b/openedx/core/djangolib/tests/test_markup.py
index 523f82de3c..e0a7b603b7 100644
--- a/openedx/core/djangolib/tests/test_markup.py
+++ b/openedx/core/djangolib/tests/test_markup.py
@@ -6,9 +6,10 @@ Tests for openedx.core.djangolib.markup
import unittest
import ddt
+from django.utils.translation import ugettext as _, ungettext
from mako.template import Template
-from openedx.core.djangolib.markup import escape, HTML, ugettext as _, ungettext
+from openedx.core.djangolib.markup import Text, HTML
@ddt.ddt
@@ -24,12 +25,12 @@ class FormatHtmlTest(unittest.TestCase):
(u"
нтмℓ-єѕ¢αρє∂", u"<a>нтмℓ-єѕ¢αρє∂</a>"),
)
def test_simple(self, (before, after)):
- self.assertEqual(unicode(_(before)), after) # pylint: disable=translation-of-non-string
- self.assertEqual(unicode(escape(before)), after)
+ self.assertEqual(unicode(Text(_(before))), after) # pylint: disable=translation-of-non-string
+ self.assertEqual(unicode(Text(before)), after)
def test_formatting(self):
# The whole point of this function is to make sure this works:
- out = _(u"Point & click {start}here{end}!").format(
+ out = Text(_(u"Point & click {start}here{end}!")).format(
start=HTML("
"),
end=HTML(""),
)
@@ -41,7 +42,7 @@ class FormatHtmlTest(unittest.TestCase):
def test_nested_formatting(self):
# Sometimes, you have plain text, with html inserted, and the html has
# plain text inserted. It gets twisty...
- out = _(u"Send {start}email{end}").format(
+ out = Text(_(u"Send {start}email{end}")).format(
start=HTML("
").format(email="A&B"),
end=HTML(""),
)
@@ -54,8 +55,12 @@ class FormatHtmlTest(unittest.TestCase):
# The default_filters used here have to match the ones in edxmako.
template = Template(
"""
- <%! from openedx.core.djangolib.markup import HTML, ugettext as _ %>
- ${_(u"A & {BC}").format(BC=HTML("B & C"))}
+ <%!
+ from django.utils.translation import ugettext as _
+
+ from openedx.core.djangolib.markup import Text, HTML
+ %>
+ ${Text(_(u"A & {BC}")).format(BC=HTML("B & C"))}
""",
default_filters=['decode.utf8', 'h'],
)
@@ -64,5 +69,5 @@ class FormatHtmlTest(unittest.TestCase):
def test_ungettext(self):
for i in [1, 2]:
- out = ungettext("1 & {}", "2 & {}", i).format(HTML("<>"))
+ out = Text(ungettext("1 & {}", "2 & {}", i)).format(HTML("<>"))
self.assertEqual(out, "{} & <>".format(i))