From ad7ddc4291ddeeee7c798fd1ca2c647e794c2e72 Mon Sep 17 00:00:00 2001 From: drevutskyj Date: Tue, 26 Apr 2016 15:04:22 +0300 Subject: [PATCH 1/3] Fix tinymce widget for modeltranslation tabs --- tinymce/widgets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tinymce/widgets.py b/tinymce/widgets.py index d85b01a2..e0bcc3b4 100644 --- a/tinymce/widgets.py +++ b/tinymce/widgets.py @@ -87,7 +87,7 @@ def render(self, name, value, attrs=None): value = smart_unicode(value) final_attrs = self.build_attrs(attrs) final_attrs['name'] = name - final_attrs['class'] = 'tinymce' + 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 = self.get_mce_json(mce_config) From 3df97c705189a4ebb8df1decb0a9ed52f0c7b553 Mon Sep 17 00:00:00 2001 From: drevutskyj Date: Fri, 6 May 2016 12:43:38 +0300 Subject: [PATCH 2/3] add check for tinymce widget attribute class --- tinymce/widgets.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tinymce/widgets.py b/tinymce/widgets.py index e0bcc3b4..d09c708e 100644 --- a/tinymce/widgets.py +++ b/tinymce/widgets.py @@ -14,6 +14,7 @@ from django.core.urlresolvers import reverse from django.forms.widgets import flatatt from django.utils.html import escape + try: from collections import OrderedDict as SortedDict except ImportError: @@ -21,6 +22,7 @@ from django.utils.safestring import mark_safe from django.utils.translation import get_language, ugettext as _ import json + try: from django.utils.encoding import smart_text as smart_unicode except ImportError: @@ -47,6 +49,7 @@ class TinyMCE(forms.Textarea): the current Django language, the others from the 'content_language' parameter. """ + def __init__(self, content_language=None, attrs=None, mce_attrs=None): super(TinyMCE, self).__init__(attrs) mce_attrs = mce_attrs or {} @@ -87,7 +90,10 @@ def render(self, name, value, attrs=None): value = smart_unicode(value) final_attrs = self.build_attrs(attrs) final_attrs['name'] = name - final_attrs['class'] = ' '.join(final_attrs['class'].split(' ') + ['tinymce']) + if final_attrs.get('class', None) is None: + final_attrs['class'] = 'tinymce' + else: + 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 = self.get_mce_json(mce_config) @@ -113,6 +119,7 @@ def _media(self): js.append(reverse('tinymce-filebrowser')) js.append('django_tinymce/init_tinymce.js') return forms.Media(js=js) + media = property(_media) From f4f2d11e2ebb9ce95a0fa8751aa39fd63a391dce Mon Sep 17 00:00:00 2001 From: drevutskyj Date: Fri, 6 May 2016 13:33:07 +0300 Subject: [PATCH 3/3] add test --- tinymce/tests/test_widgets.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tinymce/tests/test_widgets.py b/tinymce/tests/test_widgets.py index f58208ad..34cf9122 100644 --- a/tinymce/tests/test_widgets.py +++ b/tinymce/tests/test_widgets.py @@ -49,3 +49,7 @@ def test_tinymce_widget(self): self.assertIn('name="foobar"', html) self.assertIn('lorem ipsum', html) self.assertIn('class="tinymce"', html) + html = widget.render( + 'foobar', 'lorem ipsum', attrs={'id': 'id_foobar', 'class': 'foo'} + ) + self.assertIn('class="foo tinymce"', html)