equal
deleted
inserted
replaced
29 from django.forms import widgets |
29 from django.forms import widgets |
30 from django.utils import html |
30 from django.utils import html |
31 from django.utils import simplejson |
31 from django.utils import simplejson |
32 from django.utils import safestring |
32 from django.utils import safestring |
33 |
33 |
|
34 from soc.logic import dicts |
|
35 |
34 |
36 |
35 class ReadOnlyInput(forms.widgets.Input): |
37 class ReadOnlyInput(forms.widgets.Input): |
36 """Read only input widget. |
38 """Read only input widget. |
37 """ |
39 """ |
38 input_type = 'text' |
40 input_type = 'text' |
43 attrs['readonly'] = 'readonly' |
45 attrs['readonly'] = 'readonly' |
44 attrs['class'] = 'plaintext' |
46 attrs['class'] = 'plaintext' |
45 return super(ReadOnlyInput, self).render(name, value, attrs) |
47 return super(ReadOnlyInput, self).render(name, value, attrs) |
46 |
48 |
47 |
49 |
48 class TinyMCE(forms.widgets.Textarea): |
50 class FullTinyMCE(forms.widgets.Textarea): |
49 """TinyMCE widget. |
51 """TinyMCE widget. |
50 |
52 |
51 Requires to include tiny_mce_src.js in your template. Widget can be |
53 Requires to include tiny_mce_src.js in your template. Widget can be |
52 customized by overwriting or adding extra options to mce_settings |
54 customized by overwriting or adding extra options to mce_settings |
53 dictionary |
55 dictionary |
92 |
94 |
93 Args: |
95 Args: |
94 mce_settings: dict with TinyMCE widget settings |
96 mce_settings: dict with TinyMCE widget settings |
95 *args, **kwargs: passed through to parent __init__() constructor |
97 *args, **kwargs: passed through to parent __init__() constructor |
96 """ |
98 """ |
|
99 |
97 super(forms.widgets.Textarea, self).__init__(*args, **kwargs) |
100 super(forms.widgets.Textarea, self).__init__(*args, **kwargs) |
98 |
101 self.mce_settings = self.DEF_MCE_SETTINGS |
99 # copy the class defaults to an instance data member |
|
100 self.mce_settings = copy.deepcopy(self.DEF_MCE_SETTINGS) |
|
101 |
|
102 if mce_settings: |
|
103 # modify the per-instance settings if called supplied customizations |
|
104 self.mce_settings.update(mce_settings) |
|
105 |
102 |
106 def render(self, name, value, attrs=None): |
103 def render(self, name, value, attrs=None): |
107 """Render TinyMCE widget as HTML. |
104 """Render TinyMCE widget as HTML. |
108 """ |
105 """ |
109 if value is None: |
106 if value is None: |
120 {'attrs': widgets.flatatt(final_attrs), |
117 {'attrs': widgets.flatatt(final_attrs), |
121 'value': html.escape(value), |
118 'value': html.escape(value), |
122 'settings_json': mce_json}) |
119 'settings_json': mce_json}) |
123 |
120 |
124 |
121 |
|
122 class TinyMCE(FullTinyMCE): |
|
123 """Regular version of TinyMce |
|
124 """ |
|
125 |
|
126 def __init__(self, *args, **kwargs): |
|
127 """ |
|
128 """ |
|
129 |
|
130 super(TinyMCE, self).__init__(*args, **kwargs) |
|
131 keys = ['mode', 'theme', 'theme_advanced_toolbar_location', |
|
132 'theme_advanced_toolbar_align'] |
|
133 self.mce_settings = dicts.filter(self.mce_settings, keys) |
|
134 |
125 class ReferenceField(forms.CharField): |
135 class ReferenceField(forms.CharField): |
126 """Widget for selecting a reference to an Entity. |
136 """Widget for selecting a reference to an Entity. |
127 """ |
137 """ |
128 |
138 |
129 def __init__(self, reference_url, filter=None, |
139 def __init__(self, reference_url, filter=None, |