author | Sverre Rabbelier <srabbelier@gmail.com> |
Wed, 28 Jan 2009 15:24:02 +0000 | |
changeset 1037 | f706ac5beccf |
parent 841 | 9dac40accd06 |
child 1158 | eefda5105ecd |
permissions | -rw-r--r-- |
127
70206a64da4a
Created custom_widgets.py and added TinyMCE django widget that can be later used for particular form fields.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/python2.5 |
70206a64da4a
Created custom_widgets.py and added TinyMCE django widget that can be later used for particular form fields.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
2 |
# |
70206a64da4a
Created custom_widgets.py and added TinyMCE django widget that can be later used for particular form fields.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
3 |
# Copyright 2008 the Melange authors. |
70206a64da4a
Created custom_widgets.py and added TinyMCE django widget that can be later used for particular form fields.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
4 |
# |
70206a64da4a
Created custom_widgets.py and added TinyMCE django widget that can be later used for particular form fields.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
5 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
70206a64da4a
Created custom_widgets.py and added TinyMCE django widget that can be later used for particular form fields.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
6 |
# you may not use this file except in compliance with the License. |
70206a64da4a
Created custom_widgets.py and added TinyMCE django widget that can be later used for particular form fields.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
7 |
# You may obtain a copy of the License at |
70206a64da4a
Created custom_widgets.py and added TinyMCE django widget that can be later used for particular form fields.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
8 |
# |
70206a64da4a
Created custom_widgets.py and added TinyMCE django widget that can be later used for particular form fields.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
70206a64da4a
Created custom_widgets.py and added TinyMCE django widget that can be later used for particular form fields.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
10 |
# |
70206a64da4a
Created custom_widgets.py and added TinyMCE django widget that can be later used for particular form fields.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
11 |
# Unless required by applicable law or agreed to in writing, software |
70206a64da4a
Created custom_widgets.py and added TinyMCE django widget that can be later used for particular form fields.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
70206a64da4a
Created custom_widgets.py and added TinyMCE django widget that can be later used for particular form fields.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
70206a64da4a
Created custom_widgets.py and added TinyMCE django widget that can be later used for particular form fields.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
14 |
# See the License for the specific language governing permissions and |
70206a64da4a
Created custom_widgets.py and added TinyMCE django widget that can be later used for particular form fields.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
15 |
# limitations under the License. |
70206a64da4a
Created custom_widgets.py and added TinyMCE django widget that can be later used for particular form fields.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
16 |
|
70206a64da4a
Created custom_widgets.py and added TinyMCE django widget that can be later used for particular form fields.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
17 |
"""Custom widgets used for form fields. |
70206a64da4a
Created custom_widgets.py and added TinyMCE django widget that can be later used for particular form fields.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
18 |
""" |
70206a64da4a
Created custom_widgets.py and added TinyMCE django widget that can be later used for particular form fields.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
19 |
|
70206a64da4a
Created custom_widgets.py and added TinyMCE django widget that can be later used for particular form fields.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
20 |
__authors__ = [ |
70206a64da4a
Created custom_widgets.py and added TinyMCE django widget that can be later used for particular form fields.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
21 |
'"Pawel Solyga" <pawel.solyga@gmail.com>', |
70206a64da4a
Created custom_widgets.py and added TinyMCE django widget that can be later used for particular form fields.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
22 |
] |
70206a64da4a
Created custom_widgets.py and added TinyMCE django widget that can be later used for particular form fields.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
23 |
|
264
97b60788cb9a
Change to imports to follow the style guide:
Todd Larsen <tlarsen@google.com>
parents:
215
diff
changeset
|
24 |
|
97b60788cb9a
Change to imports to follow the style guide:
Todd Larsen <tlarsen@google.com>
parents:
215
diff
changeset
|
25 |
import copy |
97b60788cb9a
Change to imports to follow the style guide:
Todd Larsen <tlarsen@google.com>
parents:
215
diff
changeset
|
26 |
|
324
05e21c089be6
Add missing import in soc/views/site/sponsor/list.py which caused exception when app was deployed and first site you visited was "List Site Sponsors". Update files according to recent django update and django backwards incompatibility (for example newforms is changed to forms).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
274
diff
changeset
|
27 |
from django import forms |
05e21c089be6
Add missing import in soc/views/site/sponsor/list.py which caused exception when app was deployed and first site you visited was "List Site Sponsors". Update files according to recent django update and django backwards incompatibility (for example newforms is changed to forms).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
274
diff
changeset
|
28 |
from django.forms import util |
05e21c089be6
Add missing import in soc/views/site/sponsor/list.py which caused exception when app was deployed and first site you visited was "List Site Sponsors". Update files according to recent django update and django backwards incompatibility (for example newforms is changed to forms).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
274
diff
changeset
|
29 |
from django.forms import widgets |
264
97b60788cb9a
Change to imports to follow the style guide:
Todd Larsen <tlarsen@google.com>
parents:
215
diff
changeset
|
30 |
from django.utils import html |
127
70206a64da4a
Created custom_widgets.py and added TinyMCE django widget that can be later used for particular form fields.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
31 |
from django.utils import simplejson |
264
97b60788cb9a
Change to imports to follow the style guide:
Todd Larsen <tlarsen@google.com>
parents:
215
diff
changeset
|
32 |
from django.utils import safestring |
127
70206a64da4a
Created custom_widgets.py and added TinyMCE django widget that can be later used for particular form fields.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
33 |
|
215
d020c95b17b1
Clean up too long lines in profile.py. Add ReadOnlyInput widget to custom_widgets module, it can be used to display read-only form fields. Display read-only "Id" field in LookUp view if user has been found and in User Edit Developer view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
211
diff
changeset
|
34 |
|
d020c95b17b1
Clean up too long lines in profile.py. Add ReadOnlyInput widget to custom_widgets module, it can be used to display read-only form fields. Display read-only "Id" field in LookUp view if user has been found and in User Edit Developer view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
211
diff
changeset
|
35 |
class ReadOnlyInput(forms.widgets.Input): |
d020c95b17b1
Clean up too long lines in profile.py. Add ReadOnlyInput widget to custom_widgets module, it can be used to display read-only form fields. Display read-only "Id" field in LookUp view if user has been found and in User Edit Developer view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
211
diff
changeset
|
36 |
"""Read only input widget. |
d020c95b17b1
Clean up too long lines in profile.py. Add ReadOnlyInput widget to custom_widgets module, it can be used to display read-only form fields. Display read-only "Id" field in LookUp view if user has been found and in User Edit Developer view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
211
diff
changeset
|
37 |
""" |
d020c95b17b1
Clean up too long lines in profile.py. Add ReadOnlyInput widget to custom_widgets module, it can be used to display read-only form fields. Display read-only "Id" field in LookUp view if user has been found and in User Edit Developer view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
211
diff
changeset
|
38 |
input_type = 'text' |
d020c95b17b1
Clean up too long lines in profile.py. Add ReadOnlyInput widget to custom_widgets module, it can be used to display read-only form fields. Display read-only "Id" field in LookUp view if user has been found and in User Edit Developer view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
211
diff
changeset
|
39 |
|
d020c95b17b1
Clean up too long lines in profile.py. Add ReadOnlyInput widget to custom_widgets module, it can be used to display read-only form fields. Display read-only "Id" field in LookUp view if user has been found and in User Edit Developer view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
211
diff
changeset
|
40 |
def render(self, name, value, attrs=None): |
d020c95b17b1
Clean up too long lines in profile.py. Add ReadOnlyInput widget to custom_widgets module, it can be used to display read-only form fields. Display read-only "Id" field in LookUp view if user has been found and in User Edit Developer view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
211
diff
changeset
|
41 |
"""Render ReadOnlyInput widget as HTML. |
d020c95b17b1
Clean up too long lines in profile.py. Add ReadOnlyInput widget to custom_widgets module, it can be used to display read-only form fields. Display read-only "Id" field in LookUp view if user has been found and in User Edit Developer view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
211
diff
changeset
|
42 |
""" |
d020c95b17b1
Clean up too long lines in profile.py. Add ReadOnlyInput widget to custom_widgets module, it can be used to display read-only form fields. Display read-only "Id" field in LookUp view if user has been found and in User Edit Developer view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
211
diff
changeset
|
43 |
attrs['readonly'] = 'readonly' |
d020c95b17b1
Clean up too long lines in profile.py. Add ReadOnlyInput widget to custom_widgets module, it can be used to display read-only form fields. Display read-only "Id" field in LookUp view if user has been found and in User Edit Developer view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
211
diff
changeset
|
44 |
return super(ReadOnlyInput, self).render(name, value, attrs) |
d020c95b17b1
Clean up too long lines in profile.py. Add ReadOnlyInput widget to custom_widgets module, it can be used to display read-only form fields. Display read-only "Id" field in LookUp view if user has been found and in User Edit Developer view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
211
diff
changeset
|
45 |
|
127
70206a64da4a
Created custom_widgets.py and added TinyMCE django widget that can be later used for particular form fields.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
46 |
|
812
36280f137731
Add read-only boolean form field widget.
Todd Larsen <tlarsen@google.com>
parents:
499
diff
changeset
|
47 |
class ReadOnlyBool(forms.widgets.Input): |
36280f137731
Add read-only boolean form field widget.
Todd Larsen <tlarsen@google.com>
parents:
499
diff
changeset
|
48 |
"""Read only checkbox widget. |
36280f137731
Add read-only boolean form field widget.
Todd Larsen <tlarsen@google.com>
parents:
499
diff
changeset
|
49 |
""" |
841
9dac40accd06
Changing ReadOnlyBool to type "text" makes it display "True" or "False".
Todd Larsen <tlarsen@google.com>
parents:
812
diff
changeset
|
50 |
input_type = 'text' |
812
36280f137731
Add read-only boolean form field widget.
Todd Larsen <tlarsen@google.com>
parents:
499
diff
changeset
|
51 |
|
36280f137731
Add read-only boolean form field widget.
Todd Larsen <tlarsen@google.com>
parents:
499
diff
changeset
|
52 |
def render(self, name, value, attrs=None): |
36280f137731
Add read-only boolean form field widget.
Todd Larsen <tlarsen@google.com>
parents:
499
diff
changeset
|
53 |
"""Render ReadOnlyBool widget as HTML. |
841
9dac40accd06
Changing ReadOnlyBool to type "text" makes it display "True" or "False".
Todd Larsen <tlarsen@google.com>
parents:
812
diff
changeset
|
54 |
|
9dac40accd06
Changing ReadOnlyBool to type "text" makes it display "True" or "False".
Todd Larsen <tlarsen@google.com>
parents:
812
diff
changeset
|
55 |
Displays "text" field like ReadOnlyInput, but contents will be one of: |
9dac40accd06
Changing ReadOnlyBool to type "text" makes it display "True" or "False".
Todd Larsen <tlarsen@google.com>
parents:
812
diff
changeset
|
56 |
* empty (no text at all, just a greyed-out box) if no answer at all |
9dac40accd06
Changing ReadOnlyBool to type "text" makes it display "True" or "False".
Todd Larsen <tlarsen@google.com>
parents:
812
diff
changeset
|
57 |
* "True" (in the same greyed-out box) if True |
9dac40accd06
Changing ReadOnlyBool to type "text" makes it display "True" or "False".
Todd Larsen <tlarsen@google.com>
parents:
812
diff
changeset
|
58 |
* "False" (in the same greyed-out box) if False |
812
36280f137731
Add read-only boolean form field widget.
Todd Larsen <tlarsen@google.com>
parents:
499
diff
changeset
|
59 |
""" |
36280f137731
Add read-only boolean form field widget.
Todd Larsen <tlarsen@google.com>
parents:
499
diff
changeset
|
60 |
attrs['readonly'] = 'readonly' |
36280f137731
Add read-only boolean form field widget.
Todd Larsen <tlarsen@google.com>
parents:
499
diff
changeset
|
61 |
return super(ReadOnlyBool, self).render(name, value, attrs) |
36280f137731
Add read-only boolean form field widget.
Todd Larsen <tlarsen@google.com>
parents:
499
diff
changeset
|
62 |
|
36280f137731
Add read-only boolean form field widget.
Todd Larsen <tlarsen@google.com>
parents:
499
diff
changeset
|
63 |
|
215
d020c95b17b1
Clean up too long lines in profile.py. Add ReadOnlyInput widget to custom_widgets module, it can be used to display read-only form fields. Display read-only "Id" field in LookUp view if user has been found and in User Edit Developer view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
211
diff
changeset
|
64 |
class TinyMCE(forms.widgets.Textarea): |
d020c95b17b1
Clean up too long lines in profile.py. Add ReadOnlyInput widget to custom_widgets module, it can be used to display read-only form fields. Display read-only "Id" field in LookUp view if user has been found and in User Edit Developer view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
211
diff
changeset
|
65 |
"""TinyMCE widget. |
d020c95b17b1
Clean up too long lines in profile.py. Add ReadOnlyInput widget to custom_widgets module, it can be used to display read-only form fields. Display read-only "Id" field in LookUp view if user has been found and in User Edit Developer view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
211
diff
changeset
|
66 |
|
d020c95b17b1
Clean up too long lines in profile.py. Add ReadOnlyInput widget to custom_widgets module, it can be used to display read-only form fields. Display read-only "Id" field in LookUp view if user has been found and in User Edit Developer view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
211
diff
changeset
|
67 |
Requires to include tiny_mce_src.js in your template. Widget can be |
d020c95b17b1
Clean up too long lines in profile.py. Add ReadOnlyInput widget to custom_widgets module, it can be used to display read-only form fields. Display read-only "Id" field in LookUp view if user has been found and in User Edit Developer view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
211
diff
changeset
|
68 |
customized by overwriting or adding extra options to mce_settings |
d020c95b17b1
Clean up too long lines in profile.py. Add ReadOnlyInput widget to custom_widgets module, it can be used to display read-only form fields. Display read-only "Id" field in LookUp view if user has been found and in User Edit Developer view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
211
diff
changeset
|
69 |
dictionary |
127
70206a64da4a
Created custom_widgets.py and added TinyMCE django widget that can be later used for particular form fields.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
70 |
|
215
d020c95b17b1
Clean up too long lines in profile.py. Add ReadOnlyInput widget to custom_widgets module, it can be used to display read-only form fields. Display read-only "Id" field in LookUp view if user has been found and in User Edit Developer view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
211
diff
changeset
|
71 |
You can set TinyMCE widget for particular form field using code below: |
408
7cd6bdfbf95c
Inherit from BaseForm in all forms instead of from DbModelForm. This change doesn't include changes to templates and usage of as_table everywhere (work in progress).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
345
diff
changeset
|
72 |
class ExampleForm(helper.forms.BaseForm): |
271
01e90bb21b7e
Replace helpers/custom_widgets.py with helper/widgets.py.
Todd Larsen <tlarsen@google.com>
parents:
264
diff
changeset
|
73 |
content = forms.fields.CharField(widget=helper.widgets.TinyMCE()) |
215
d020c95b17b1
Clean up too long lines in profile.py. Add ReadOnlyInput widget to custom_widgets module, it can be used to display read-only form fields. Display read-only "Id" field in LookUp view if user has been found and in User Edit Developer view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
211
diff
changeset
|
74 |
|
d020c95b17b1
Clean up too long lines in profile.py. Add ReadOnlyInput widget to custom_widgets module, it can be used to display read-only form fields. Display read-only "Id" field in LookUp view if user has been found and in User Edit Developer view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
211
diff
changeset
|
75 |
You can include tiny_mce_src.js in your template using: |
d020c95b17b1
Clean up too long lines in profile.py. Add ReadOnlyInput widget to custom_widgets module, it can be used to display read-only form fields. Display read-only "Id" field in LookUp view if user has been found and in User Edit Developer view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
211
diff
changeset
|
76 |
{% block scripts %} |
d020c95b17b1
Clean up too long lines in profile.py. Add ReadOnlyInput widget to custom_widgets module, it can be used to display read-only form fields. Display read-only "Id" field in LookUp view if user has been found and in User Edit Developer view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
211
diff
changeset
|
77 |
<script type="text/javascript" src="/tiny_mce/tiny_mce_src.js"></script> |
d020c95b17b1
Clean up too long lines in profile.py. Add ReadOnlyInput widget to custom_widgets module, it can be used to display read-only form fields. Display read-only "Id" field in LookUp view if user has been found and in User Edit Developer view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
211
diff
changeset
|
78 |
{% endblock %} |
d020c95b17b1
Clean up too long lines in profile.py. Add ReadOnlyInput widget to custom_widgets module, it can be used to display read-only form fields. Display read-only "Id" field in LookUp view if user has been found and in User Edit Developer view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
211
diff
changeset
|
79 |
""" |
127
70206a64da4a
Created custom_widgets.py and added TinyMCE django widget that can be later used for particular form fields.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
80 |
|
345
27c3c63da9ac
Update TinyMCE wiget code according to r783. I hope I did it correctly this time.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
335
diff
changeset
|
81 |
DEF_MCE_SETTINGS = {'mode': "exact", |
27c3c63da9ac
Update TinyMCE wiget code according to r783. I hope I did it correctly this time.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
335
diff
changeset
|
82 |
'theme': "simple", |
27c3c63da9ac
Update TinyMCE wiget code according to r783. I hope I did it correctly this time.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
335
diff
changeset
|
83 |
'theme_advanced_toolbar_location': "top", |
27c3c63da9ac
Update TinyMCE wiget code according to r783. I hope I did it correctly this time.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
335
diff
changeset
|
84 |
'theme_advanced_toolbar_align': "center"} |
215
d020c95b17b1
Clean up too long lines in profile.py. Add ReadOnlyInput widget to custom_widgets module, it can be used to display read-only form fields. Display read-only "Id" field in LookUp view if user has been found and in User Edit Developer view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
211
diff
changeset
|
85 |
|
d020c95b17b1
Clean up too long lines in profile.py. Add ReadOnlyInput widget to custom_widgets module, it can be used to display read-only form fields. Display read-only "Id" field in LookUp view if user has been found and in User Edit Developer view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
211
diff
changeset
|
86 |
TINY_MCE_HTML_FMT = u'''\ |
194
8bdb1d2d0c36
Change indentation level to 2 (from 4) and rename MCE_DEF_SETTINGS to
Todd Larsen <tlarsen@google.com>
parents:
188
diff
changeset
|
87 |
<textarea %(attrs)s>%(value)s</textarea> |
8bdb1d2d0c36
Change indentation level to 2 (from 4) and rename MCE_DEF_SETTINGS to
Todd Larsen <tlarsen@google.com>
parents:
188
diff
changeset
|
88 |
<script type="text/javascript"> |
215
d020c95b17b1
Clean up too long lines in profile.py. Add ReadOnlyInput widget to custom_widgets module, it can be used to display read-only form fields. Display read-only "Id" field in LookUp view if user has been found and in User Edit Developer view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
211
diff
changeset
|
89 |
tinyMCE.init(%(settings_json)s) |
194
8bdb1d2d0c36
Change indentation level to 2 (from 4) and rename MCE_DEF_SETTINGS to
Todd Larsen <tlarsen@google.com>
parents:
188
diff
changeset
|
90 |
</script>''' |
335
9c1a6e02ebec
Changes to TinyMCE widget that enable to pass mce_settings in the class constructor and that way update default settings if needed.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
324
diff
changeset
|
91 |
|
9c1a6e02ebec
Changes to TinyMCE widget that enable to pass mce_settings in the class constructor and that way update default settings if needed.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
324
diff
changeset
|
92 |
def __init__(self, mce_settings=None, *args, **kwargs): |
499
d22e4fe8e64b
Fix missing dots in doc strings and some other doc string corrections.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
408
diff
changeset
|
93 |
"""Initialize TinyMCE widget with default or customized settings. |
335
9c1a6e02ebec
Changes to TinyMCE widget that enable to pass mce_settings in the class constructor and that way update default settings if needed.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
324
diff
changeset
|
94 |
|
9c1a6e02ebec
Changes to TinyMCE widget that enable to pass mce_settings in the class constructor and that way update default settings if needed.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
324
diff
changeset
|
95 |
Args: |
9c1a6e02ebec
Changes to TinyMCE widget that enable to pass mce_settings in the class constructor and that way update default settings if needed.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
324
diff
changeset
|
96 |
mce_settings: dict with TinyMCE widget settings |
9c1a6e02ebec
Changes to TinyMCE widget that enable to pass mce_settings in the class constructor and that way update default settings if needed.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
324
diff
changeset
|
97 |
*args, **kwargs: passed through to parent __init__() constructor |
9c1a6e02ebec
Changes to TinyMCE widget that enable to pass mce_settings in the class constructor and that way update default settings if needed.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
324
diff
changeset
|
98 |
""" |
9c1a6e02ebec
Changes to TinyMCE widget that enable to pass mce_settings in the class constructor and that way update default settings if needed.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
324
diff
changeset
|
99 |
super(forms.widgets.Textarea, self).__init__(*args, **kwargs) |
9c1a6e02ebec
Changes to TinyMCE widget that enable to pass mce_settings in the class constructor and that way update default settings if needed.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
324
diff
changeset
|
100 |
|
345
27c3c63da9ac
Update TinyMCE wiget code according to r783. I hope I did it correctly this time.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
335
diff
changeset
|
101 |
# copy the class defaults to an instance data member |
27c3c63da9ac
Update TinyMCE wiget code according to r783. I hope I did it correctly this time.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
335
diff
changeset
|
102 |
self.mce_settings = copy.deepcopy(self.DEF_MCE_SETTINGS) |
27c3c63da9ac
Update TinyMCE wiget code according to r783. I hope I did it correctly this time.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
335
diff
changeset
|
103 |
|
335
9c1a6e02ebec
Changes to TinyMCE widget that enable to pass mce_settings in the class constructor and that way update default settings if needed.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
324
diff
changeset
|
104 |
if mce_settings: |
345
27c3c63da9ac
Update TinyMCE wiget code according to r783. I hope I did it correctly this time.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
335
diff
changeset
|
105 |
# modify the per-instance settings if called supplied customizations |
335
9c1a6e02ebec
Changes to TinyMCE widget that enable to pass mce_settings in the class constructor and that way update default settings if needed.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
324
diff
changeset
|
106 |
self.mce_settings.update(mce_settings) |
215
d020c95b17b1
Clean up too long lines in profile.py. Add ReadOnlyInput widget to custom_widgets module, it can be used to display read-only form fields. Display read-only "Id" field in LookUp view if user has been found and in User Edit Developer view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
211
diff
changeset
|
107 |
|
d020c95b17b1
Clean up too long lines in profile.py. Add ReadOnlyInput widget to custom_widgets module, it can be used to display read-only form fields. Display read-only "Id" field in LookUp view if user has been found and in User Edit Developer view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
211
diff
changeset
|
108 |
def render(self, name, value, attrs=None): |
d020c95b17b1
Clean up too long lines in profile.py. Add ReadOnlyInput widget to custom_widgets module, it can be used to display read-only form fields. Display read-only "Id" field in LookUp view if user has been found and in User Edit Developer view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
211
diff
changeset
|
109 |
"""Render TinyMCE widget as HTML. |
d020c95b17b1
Clean up too long lines in profile.py. Add ReadOnlyInput widget to custom_widgets module, it can be used to display read-only form fields. Display read-only "Id" field in LookUp view if user has been found and in User Edit Developer view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
211
diff
changeset
|
110 |
""" |
d020c95b17b1
Clean up too long lines in profile.py. Add ReadOnlyInput widget to custom_widgets module, it can be used to display read-only form fields. Display read-only "Id" field in LookUp view if user has been found and in User Edit Developer view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
211
diff
changeset
|
111 |
if value is None: |
d020c95b17b1
Clean up too long lines in profile.py. Add ReadOnlyInput widget to custom_widgets module, it can be used to display read-only form fields. Display read-only "Id" field in LookUp view if user has been found and in User Edit Developer view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
211
diff
changeset
|
112 |
value = '' |
264
97b60788cb9a
Change to imports to follow the style guide:
Todd Larsen <tlarsen@google.com>
parents:
215
diff
changeset
|
113 |
value = util.smart_unicode(value) |
215
d020c95b17b1
Clean up too long lines in profile.py. Add ReadOnlyInput widget to custom_widgets module, it can be used to display read-only form fields. Display read-only "Id" field in LookUp view if user has been found and in User Edit Developer view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
211
diff
changeset
|
114 |
final_attrs = self.build_attrs(attrs, name=name) |
188
27ed1a09c98d
Changes in TinyMCE widget in custom_widgets.py based on review comments.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
141
diff
changeset
|
115 |
|
215
d020c95b17b1
Clean up too long lines in profile.py. Add ReadOnlyInput widget to custom_widgets module, it can be used to display read-only form fields. Display read-only "Id" field in LookUp view if user has been found and in User Edit Developer view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
211
diff
changeset
|
116 |
self.mce_settings['elements'] = "id_%s" % name |
211
ec26682053df
Made mce_settings class variable in TinyMCE widget a copy of default settings instead of reference.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
194
diff
changeset
|
117 |
|
215
d020c95b17b1
Clean up too long lines in profile.py. Add ReadOnlyInput widget to custom_widgets module, it can be used to display read-only form fields. Display read-only "Id" field in LookUp view if user has been found and in User Edit Developer view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
211
diff
changeset
|
118 |
# convert mce_settings from dict to JSON |
d020c95b17b1
Clean up too long lines in profile.py. Add ReadOnlyInput widget to custom_widgets module, it can be used to display read-only form fields. Display read-only "Id" field in LookUp view if user has been found and in User Edit Developer view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
211
diff
changeset
|
119 |
mce_json = simplejson.JSONEncoder().encode(self.mce_settings) |
127
70206a64da4a
Created custom_widgets.py and added TinyMCE django widget that can be later used for particular form fields.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
120 |
|
264
97b60788cb9a
Change to imports to follow the style guide:
Todd Larsen <tlarsen@google.com>
parents:
215
diff
changeset
|
121 |
return safestring.mark_safe(self.TINY_MCE_HTML_FMT % |
97b60788cb9a
Change to imports to follow the style guide:
Todd Larsen <tlarsen@google.com>
parents:
215
diff
changeset
|
122 |
{'attrs': widgets.flatatt(final_attrs), |
97b60788cb9a
Change to imports to follow the style guide:
Todd Larsen <tlarsen@google.com>
parents:
215
diff
changeset
|
123 |
'value': html.escape(value), |
215
d020c95b17b1
Clean up too long lines in profile.py. Add ReadOnlyInput widget to custom_widgets module, it can be used to display read-only form fields. Display read-only "Id" field in LookUp view if user has been found and in User Edit Developer view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
211
diff
changeset
|
124 |
'settings_json': mce_json}) |