Skip to content

Commit

Permalink
Added support for translated options
Browse files Browse the repository at this point in the history
  • Loading branch information
mireq authored and claudep committed Jan 23, 2023
1 parent 23ef6c9 commit 1091351
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
10 changes: 9 additions & 1 deletion tests/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django import forms
from django.test import SimpleTestCase
from django.test.utils import override_settings
from django.utils.translation import override
from django.utils.translation import override, gettext_lazy

import tinymce.settings
from tinymce.widgets import TinyMCE, get_language_config
Expand Down Expand Up @@ -155,3 +155,11 @@ class TinyForm(forms.Form):

rendered = str(TinyForm())
self.assertNotIn("required", rendered)

def test_tinymce_widget_allow_translated_options(self):
widget = TinyMCE()
orig_config = tinymce.settings.DEFAULT_CONFIG
style_formats = [{'title': gettext_lazy("Awesome style"), 'inline': 'strong'}]
with patch.dict(tinymce.settings.DEFAULT_CONFIG, {**orig_config, "style_formats": style_formats}):
html = widget.render("foobar", "lorem ipsum", attrs={"id": "id_foobar"})
self.assertIn('Awesome style', html)
3 changes: 2 additions & 1 deletion tinymce/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from django import forms
from django.conf import settings
from django.contrib.admin import widgets as admin_widgets
from django.core.serializers.json import DjangoJSONEncoder
from django.forms.utils import flatatt
from django.urls import reverse
from django.utils.html import escape
Expand Down Expand Up @@ -81,7 +82,7 @@ def render(self, name, value, attrs=None, renderer=None):
final_attrs["class"] = " ".join(final_attrs["class"].split(" ") + ["tinymce"])
assert "id" in final_attrs, "TinyMCE widget attributes must contain 'id'"
mce_config = self.get_mce_config(final_attrs)
mce_json = json.dumps(mce_config)
mce_json = json.dumps(mce_config, cls=DjangoJSONEncoder)
if tinymce.settings.USE_COMPRESSOR:
compressor_config = {
"plugins": mce_config.get("plugins", ""),
Expand Down

0 comments on commit 1091351

Please sign in to comment.