Rename TinyMCE to FullTinyMCE and add TinyMCE widget
The FullTinyMCE (irony intended) is the full-fledged editor, usefull
in editing documents etc. The regular TinyMCE widget can be used for
smaller tasks that allow HTML input (such as the description field).
Patch by: Sverre Rabbelier
--- a/app/soc/views/helper/widgets.py Wed Feb 11 23:57:08 2009 +0000
+++ b/app/soc/views/helper/widgets.py Wed Feb 11 23:59:41 2009 +0000
@@ -31,6 +31,8 @@
from django.utils import simplejson
from django.utils import safestring
+from soc.logic import dicts
+
class ReadOnlyInput(forms.widgets.Input):
"""Read only input widget.
@@ -45,7 +47,7 @@
return super(ReadOnlyInput, self).render(name, value, attrs)
-class TinyMCE(forms.widgets.Textarea):
+class FullTinyMCE(forms.widgets.Textarea):
"""TinyMCE widget.
Requires to include tiny_mce_src.js in your template. Widget can be
@@ -94,14 +96,9 @@
mce_settings: dict with TinyMCE widget settings
*args, **kwargs: passed through to parent __init__() constructor
"""
+
super(forms.widgets.Textarea, self).__init__(*args, **kwargs)
-
- # copy the class defaults to an instance data member
- self.mce_settings = copy.deepcopy(self.DEF_MCE_SETTINGS)
-
- if mce_settings:
- # modify the per-instance settings if called supplied customizations
- self.mce_settings.update(mce_settings)
+ self.mce_settings = self.DEF_MCE_SETTINGS
def render(self, name, value, attrs=None):
"""Render TinyMCE widget as HTML.
@@ -122,6 +119,19 @@
'settings_json': mce_json})
+class TinyMCE(FullTinyMCE):
+ """Regular version of TinyMce
+ """
+
+ def __init__(self, *args, **kwargs):
+ """
+ """
+
+ super(TinyMCE, self).__init__(*args, **kwargs)
+ keys = ['mode', 'theme', 'theme_advanced_toolbar_location',
+ 'theme_advanced_toolbar_align']
+ self.mce_settings = dicts.filter(self.mce_settings, keys)
+
class ReferenceField(forms.CharField):
"""Widget for selecting a reference to an Entity.
"""
--- a/app/soc/views/models/document.py Wed Feb 11 23:57:08 2009 +0000
+++ b/app/soc/views/models/document.py Wed Feb 11 23:59:41 2009 +0000
@@ -86,7 +86,7 @@
new_params['create_extra_dynafields'] = {
'content': forms.fields.CharField(
- widget=helper.widgets.TinyMCE(attrs={'rows': 25, 'cols': 100})),
+ widget=helper.widgets.FullTinyMCE(attrs={'rows': 25, 'cols': 100})),
'scope_path': forms.fields.CharField(widget=forms.HiddenInput,
required=True),
'prefix': forms.fields.CharField(widget=helper.widgets.ReadOnlyInput(),