Changes to TinyMCE widget that enable to pass mce_settings in the class constructor and that way update default settings if needed.
Patch by: Pawel Solyga
Review by: to-be-reviewed
--- a/app/soc/views/helper/widgets.py Wed Oct 15 13:49:17 2008 +0000
+++ b/app/soc/views/helper/widgets.py Wed Oct 15 13:51:31 2008 +0000
@@ -60,18 +60,29 @@
<script type="text/javascript" src="/tiny_mce/tiny_mce_src.js"></script>
{% endblock %}
"""
- DEF_MCE_SETTINGS = { 'mode': "exact",
- 'theme': "simple",
- 'theme_advanced_toolbar_location': "top",
- 'theme_advanced_toolbar_align': "center"}
- mce_settings = DEF_MCE_SETTINGS.copy()
+ mce_settings = {'mode': "exact",
+ 'theme': "simple",
+ 'theme_advanced_toolbar_location': "top",
+ 'theme_advanced_toolbar_align': "center"}
TINY_MCE_HTML_FMT = u'''\
<textarea %(attrs)s>%(value)s</textarea>
<script type="text/javascript">
tinyMCE.init(%(settings_json)s)
</script>'''
+
+ def __init__(self, mce_settings=None, *args, **kwargs):
+ """Initialize TinyMCE widget with default or customized settings
+
+ Args:
+ mce_settings: dict with TinyMCE widget settings
+ *args, **kwargs: passed through to parent __init__() constructor
+ """
+ super(forms.widgets.Textarea, self).__init__(*args, **kwargs)
+
+ if mce_settings:
+ self.mce_settings.update(mce_settings)
def render(self, name, value, attrs=None):
"""Render TinyMCE widget as HTML.