diff --git a/apps/translations/tests/test_widgets.py b/apps/translations/tests/test_widgets.py
new file mode 100644
index 0000000000..3489127779
--- /dev/null
+++ b/apps/translations/tests/test_widgets.py
@@ -0,0 +1,18 @@
+from pyquery import PyQuery as pq
+import test_utils
+from nose.tools import eq_
+
+from translations import models, widgets
+
+
+class TestWidget(test_utils.TestCase):
+
+ def test_avoid_purified_translation(self):
+ # Even if we pass in a LinkifiedTranslation the widget switches to a
+ # normal Translation before rendering.
+ w = widgets.TransTextarea.widget()
+ link = models.LinkifiedTranslation(localized_string='yum yum',
+ locale='fr', id=10)
+ link.clean()
+ widget = w.render('name', link)
+ eq_(pq(widget).html(), 'yum yum')
diff --git a/apps/translations/widgets.py b/apps/translations/widgets.py
index e3adebfbd4..f48ab46a01 100644
--- a/apps/translations/widgets.py
+++ b/apps/translations/widgets.py
@@ -59,7 +59,7 @@ class TransMulti(forms.widgets.MultiWidget):
def decompress(self, value):
if not value:
return []
- elif isinstance(value, long):
+ elif isinstance(value, (long, int)):
# We got a foreign key to the translation table.
qs = Translation.objects.filter(id=value)
return list(qs.filter(localized_string__isnull=False))
@@ -103,11 +103,16 @@ class _TransWidget(object):
"""
def render(self, name, value, attrs=None):
+ from .fields import switch
attrs = self.build_attrs(attrs)
lang = to_language(value.locale)
attrs.update(lang=lang)
# Use rsplit to drop django's name_idx numbering. (name_0 => name)
name = '%s_%s' % (name.rsplit('_', 1)[0], lang)
+ # Make sure we don't get a Linkified/Purified Translation. We don't
+ # want people editing a bleached value.
+ if value.__class__ != Translation:
+ value = switch(value, Translation)
return super(_TransWidget, self).render(name, value, attrs)