author | Lennard de Rijk <ljvderijk@gmail.com> |
Thu, 30 Jul 2009 10:53:03 +0200 | |
changeset 2692 | b57572c43b32 |
parent 2077 | fd2e83a297c7 |
child 2797 | 236e5b192295 |
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 |
# |
1308
35b75ffcbb37
Partially reverted "Update the copyright notice for 2009."
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1307
diff
changeset
|
3 |
# Copyright 2008 the Melange authors. |
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
|
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>', |
1960
64fa3cf03b4e
Removed formatting from TinyMCE that use the style tag
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1778
diff
changeset
|
22 |
'"Sverre Rabbelier" <sverre@rabbelier.nl>', |
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
|
23 |
] |
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
|
24 |
|
264
97b60788cb9a
Change to imports to follow the style guide:
Todd Larsen <tlarsen@google.com>
parents:
215
diff
changeset
|
25 |
|
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
|
26 |
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
|
27 |
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
|
28 |
from django.forms import widgets |
264
97b60788cb9a
Change to imports to follow the style guide:
Todd Larsen <tlarsen@google.com>
parents:
215
diff
changeset
|
29 |
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
|
30 |
from django.utils import simplejson |
264
97b60788cb9a
Change to imports to follow the style guide:
Todd Larsen <tlarsen@google.com>
parents:
215
diff
changeset
|
31 |
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
|
32 |
|
1274
5f87d9807b77
Rename TinyMCE to FullTinyMCE and add TinyMCE widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1241
diff
changeset
|
33 |
from soc.logic import dicts |
5f87d9807b77
Rename TinyMCE to FullTinyMCE and add TinyMCE widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1241
diff
changeset
|
34 |
|
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
|
35 |
|
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 |
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
|
37 |
"""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
|
38 |
""" |
1337
77931c584199
Add a PlainTextWidget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1308
diff
changeset
|
39 |
|
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
|
40 |
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
|
41 |
|
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 |
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
|
43 |
"""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
|
44 |
""" |
1337
77931c584199
Add a PlainTextWidget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1308
diff
changeset
|
45 |
|
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
|
46 |
attrs['readonly'] = 'readonly' |
1158
eefda5105ecd
ReadOnlyInput widget now shows text instead of a greyed-out input box.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
841
diff
changeset
|
47 |
attrs['class'] = 'plaintext' |
1337
77931c584199
Add a PlainTextWidget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1308
diff
changeset
|
48 |
|
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
|
49 |
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
|
50 |
|
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
|
51 |
|
1337
77931c584199
Add a PlainTextWidget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1308
diff
changeset
|
52 |
class PlainTextWidget(forms.widgets.Widget): |
77931c584199
Add a PlainTextWidget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1308
diff
changeset
|
53 |
"""Read only input widget. |
77931c584199
Add a PlainTextWidget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1308
diff
changeset
|
54 |
""" |
77931c584199
Add a PlainTextWidget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1308
diff
changeset
|
55 |
|
77931c584199
Add a PlainTextWidget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1308
diff
changeset
|
56 |
def render(self, name, value, attrs=None): |
77931c584199
Add a PlainTextWidget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1308
diff
changeset
|
57 |
"""Render ReadOnlyInput widget as HTML. |
77931c584199
Add a PlainTextWidget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1308
diff
changeset
|
58 |
""" |
77931c584199
Add a PlainTextWidget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1308
diff
changeset
|
59 |
|
77931c584199
Add a PlainTextWidget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1308
diff
changeset
|
60 |
return str(value) if value else "" |
77931c584199
Add a PlainTextWidget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1308
diff
changeset
|
61 |
|
77931c584199
Add a PlainTextWidget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1308
diff
changeset
|
62 |
|
1274
5f87d9807b77
Rename TinyMCE to FullTinyMCE and add TinyMCE widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1241
diff
changeset
|
63 |
class FullTinyMCE(forms.widgets.Textarea): |
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 |
"""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
|
65 |
|
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 |
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
|
67 |
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
|
68 |
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
|
69 |
|
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
|
70 |
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
|
71 |
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
|
72 |
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
|
73 |
|
2013
eda2589a90e6
Use minified tiny_mce.js javascript file instead of tiny_mce_src.js which is 100kB larger.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
1997
diff
changeset
|
74 |
You can include tiny_mce.js in your template using: |
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
|
75 |
{% block scripts %} |
2013
eda2589a90e6
Use minified tiny_mce.js javascript file instead of tiny_mce_src.js which is 100kB larger.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
1997
diff
changeset
|
76 |
<script type="text/javascript" src="/tiny_mce/tiny_mce.js"></script> |
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
|
77 |
{% 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
|
78 |
""" |
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
|
79 |
|
1960
64fa3cf03b4e
Removed formatting from TinyMCE that use the style tag
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1778
diff
changeset
|
80 |
features1 = ("bold,italic,underline,strikethrough,blockquote,|," |
1241
5e25cd6abe09
Pimp TinyMCE widget.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1228
diff
changeset
|
81 |
",justifyleft,justifycenter,justifyright,justifyfull,|," |
1960
64fa3cf03b4e
Removed formatting from TinyMCE that use the style tag
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1778
diff
changeset
|
82 |
"formatselect") |
1241
5e25cd6abe09
Pimp TinyMCE widget.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1228
diff
changeset
|
83 |
|
5e25cd6abe09
Pimp TinyMCE widget.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1228
diff
changeset
|
84 |
features2 = ("newdocument,|,bullist,numlist,|,outdent,indent,|,undo,redo,|" |
5e25cd6abe09
Pimp TinyMCE widget.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1228
diff
changeset
|
85 |
",link,unlink,anchor,image,cleanup,help,code,hr,removeformat,visualaid,|," |
5e25cd6abe09
Pimp TinyMCE widget.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1228
diff
changeset
|
86 |
"sub,sup,|,charmap," |
5e25cd6abe09
Pimp TinyMCE widget.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1228
diff
changeset
|
87 |
"") |
5e25cd6abe09
Pimp TinyMCE widget.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1228
diff
changeset
|
88 |
|
1578
0ffb9a3dfbdf
Turn off relative urls and removing of script hostname in TinyMCE
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1542
diff
changeset
|
89 |
DEF_MCE_SETTINGS = { |
0ffb9a3dfbdf
Turn off relative urls and removing of script hostname in TinyMCE
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1542
diff
changeset
|
90 |
'mode': "exact", |
0ffb9a3dfbdf
Turn off relative urls and removing of script hostname in TinyMCE
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1542
diff
changeset
|
91 |
'theme': "advanced", |
0ffb9a3dfbdf
Turn off relative urls and removing of script hostname in TinyMCE
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1542
diff
changeset
|
92 |
'theme_advanced_buttons1': features1, |
0ffb9a3dfbdf
Turn off relative urls and removing of script hostname in TinyMCE
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1542
diff
changeset
|
93 |
'theme_advanced_buttons2': features2, |
0ffb9a3dfbdf
Turn off relative urls and removing of script hostname in TinyMCE
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1542
diff
changeset
|
94 |
'theme_advanced_buttons3': '', |
1997
55cf79b8cffe
Enable resizing in the TinyMCE widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1960
diff
changeset
|
95 |
'theme_advanced_resizing': True, |
1578
0ffb9a3dfbdf
Turn off relative urls and removing of script hostname in TinyMCE
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1542
diff
changeset
|
96 |
'theme_advanced_toolbar_location': "top", |
1997
55cf79b8cffe
Enable resizing in the TinyMCE widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1960
diff
changeset
|
97 |
'theme_advanced_statusbar_location': "bottom", |
55cf79b8cffe
Enable resizing in the TinyMCE widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1960
diff
changeset
|
98 |
'theme_advanced_path' : False, |
1578
0ffb9a3dfbdf
Turn off relative urls and removing of script hostname in TinyMCE
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1542
diff
changeset
|
99 |
'theme_advanced_toolbar_align': "left", |
0ffb9a3dfbdf
Turn off relative urls and removing of script hostname in TinyMCE
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1542
diff
changeset
|
100 |
'relative_urls': 0, |
0ffb9a3dfbdf
Turn off relative urls and removing of script hostname in TinyMCE
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1542
diff
changeset
|
101 |
'remove_script_host': 0, |
0ffb9a3dfbdf
Turn off relative urls and removing of script hostname in TinyMCE
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1542
diff
changeset
|
102 |
} |
1241
5e25cd6abe09
Pimp TinyMCE widget.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1228
diff
changeset
|
103 |
|
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
|
104 |
|
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
|
105 |
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
|
106 |
<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
|
107 |
<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
|
108 |
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
|
109 |
</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
|
110 |
|
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
|
111 |
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
|
112 |
"""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
|
113 |
|
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
|
114 |
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
|
115 |
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
|
116 |
*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
|
117 |
""" |
1274
5f87d9807b77
Rename TinyMCE to FullTinyMCE and add TinyMCE widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1241
diff
changeset
|
118 |
|
2077
fd2e83a297c7
Style fixes, add missing docstring, fix some wrong calls to super classes and removal of unused imports in soc.views.helper.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
2013
diff
changeset
|
119 |
super(FullTinyMCE, self).__init__(*args, **kwargs) |
1274
5f87d9807b77
Rename TinyMCE to FullTinyMCE and add TinyMCE widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1241
diff
changeset
|
120 |
self.mce_settings = self.DEF_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
|
121 |
|
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
|
122 |
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
|
123 |
"""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
|
124 |
""" |
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
|
125 |
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
|
126 |
value = '' |
264
97b60788cb9a
Change to imports to follow the style guide:
Todd Larsen <tlarsen@google.com>
parents:
215
diff
changeset
|
127 |
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
|
128 |
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
|
129 |
|
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
|
130 |
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
|
131 |
|
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
|
132 |
# 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
|
133 |
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
|
134 |
|
264
97b60788cb9a
Change to imports to follow the style guide:
Todd Larsen <tlarsen@google.com>
parents:
215
diff
changeset
|
135 |
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
|
136 |
{'attrs': widgets.flatatt(final_attrs), |
97b60788cb9a
Change to imports to follow the style guide:
Todd Larsen <tlarsen@google.com>
parents:
215
diff
changeset
|
137 |
'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
|
138 |
'settings_json': mce_json}) |
1228
b24796279fb9
Added a ReferenceField widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1158
diff
changeset
|
139 |
|
b24796279fb9
Added a ReferenceField widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1158
diff
changeset
|
140 |
|
1274
5f87d9807b77
Rename TinyMCE to FullTinyMCE and add TinyMCE widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1241
diff
changeset
|
141 |
class TinyMCE(FullTinyMCE): |
5f87d9807b77
Rename TinyMCE to FullTinyMCE and add TinyMCE widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1241
diff
changeset
|
142 |
"""Regular version of TinyMce |
5f87d9807b77
Rename TinyMCE to FullTinyMCE and add TinyMCE widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1241
diff
changeset
|
143 |
""" |
5f87d9807b77
Rename TinyMCE to FullTinyMCE and add TinyMCE widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1241
diff
changeset
|
144 |
|
5f87d9807b77
Rename TinyMCE to FullTinyMCE and add TinyMCE widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1241
diff
changeset
|
145 |
def __init__(self, *args, **kwargs): |
5f87d9807b77
Rename TinyMCE to FullTinyMCE and add TinyMCE widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1241
diff
changeset
|
146 |
""" |
5f87d9807b77
Rename TinyMCE to FullTinyMCE and add TinyMCE widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1241
diff
changeset
|
147 |
""" |
5f87d9807b77
Rename TinyMCE to FullTinyMCE and add TinyMCE widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1241
diff
changeset
|
148 |
|
5f87d9807b77
Rename TinyMCE to FullTinyMCE and add TinyMCE widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1241
diff
changeset
|
149 |
super(TinyMCE, self).__init__(*args, **kwargs) |
5f87d9807b77
Rename TinyMCE to FullTinyMCE and add TinyMCE widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1241
diff
changeset
|
150 |
keys = ['mode', 'theme', 'theme_advanced_toolbar_location', |
1578
0ffb9a3dfbdf
Turn off relative urls and removing of script hostname in TinyMCE
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1542
diff
changeset
|
151 |
'theme_advanced_toolbar_align', 'relative_urls', |
0ffb9a3dfbdf
Turn off relative urls and removing of script hostname in TinyMCE
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1542
diff
changeset
|
152 |
'remove_script_host'] |
1274
5f87d9807b77
Rename TinyMCE to FullTinyMCE and add TinyMCE widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1241
diff
changeset
|
153 |
self.mce_settings = dicts.filter(self.mce_settings, keys) |
5f87d9807b77
Rename TinyMCE to FullTinyMCE and add TinyMCE widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1241
diff
changeset
|
154 |
|
1228
b24796279fb9
Added a ReferenceField widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1158
diff
changeset
|
155 |
class ReferenceField(forms.CharField): |
b24796279fb9
Added a ReferenceField widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1158
diff
changeset
|
156 |
"""Widget for selecting a reference to an Entity. |
b24796279fb9
Added a ReferenceField widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1158
diff
changeset
|
157 |
""" |
b24796279fb9
Added a ReferenceField widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1158
diff
changeset
|
158 |
|
1301
58f18ea60093
Added a filter_fields parameter to the ReferenceField widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1275
diff
changeset
|
159 |
def __init__(self, reference_url, filter=None, filter_fields=None, |
1228
b24796279fb9
Added a ReferenceField widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1158
diff
changeset
|
160 |
*args, **kwargs): |
b24796279fb9
Added a ReferenceField widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1158
diff
changeset
|
161 |
"""Initializes the widget with the specified url and filter. |
b24796279fb9
Added a ReferenceField widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1158
diff
changeset
|
162 |
""" |
b24796279fb9
Added a ReferenceField widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1158
diff
changeset
|
163 |
|
b24796279fb9
Added a ReferenceField widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1158
diff
changeset
|
164 |
self.rf = {} |
b24796279fb9
Added a ReferenceField widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1158
diff
changeset
|
165 |
self.rf['reference_url'] = reference_url |
b24796279fb9
Added a ReferenceField widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1158
diff
changeset
|
166 |
self.rf['filter'] = filter if filter else [] |
1301
58f18ea60093
Added a filter_fields parameter to the ReferenceField widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1275
diff
changeset
|
167 |
self.rf['filter_fields'] = filter_fields if filter_fields else {} |
1228
b24796279fb9
Added a ReferenceField widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1158
diff
changeset
|
168 |
super(ReferenceField, self).__init__(*args, **kwargs) |
1275
75332102f83b
Added an AgreementField widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1274
diff
changeset
|
169 |
|
75332102f83b
Added an AgreementField widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1274
diff
changeset
|
170 |
|
75332102f83b
Added an AgreementField widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1274
diff
changeset
|
171 |
class AgreementField(widgets.Widget): |
75332102f83b
Added an AgreementField widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1274
diff
changeset
|
172 |
"""Widget for selecting a reference to an Entity. |
75332102f83b
Added an AgreementField widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1274
diff
changeset
|
173 |
""" |
75332102f83b
Added an AgreementField widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1274
diff
changeset
|
174 |
|
75332102f83b
Added an AgreementField widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1274
diff
changeset
|
175 |
HTML_CODE = """ |
75332102f83b
Added an AgreementField widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1274
diff
changeset
|
176 |
<span style="width:450px" colspan="4"> |
1593
58e7c56206cd
Make the ToS field less high
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1578
diff
changeset
|
177 |
<div id="ToS" style="overflow:auto;height:500px"> |
1725
52d90bbc98dc
Make it possible to specify a link to the full text
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1593
diff
changeset
|
178 |
%(text)s |
1275
75332102f83b
Added an AgreementField widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1274
diff
changeset
|
179 |
</div> |
75332102f83b
Added an AgreementField widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1274
diff
changeset
|
180 |
</span> |
1725
52d90bbc98dc
Make it possible to specify a link to the full text
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1593
diff
changeset
|
181 |
%(url)s |
1275
75332102f83b
Added an AgreementField widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1274
diff
changeset
|
182 |
""" |
75332102f83b
Added an AgreementField widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1274
diff
changeset
|
183 |
|
75332102f83b
Added an AgreementField widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1274
diff
changeset
|
184 |
def __init__(self, *args, **kwargs): |
75332102f83b
Added an AgreementField widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1274
diff
changeset
|
185 |
self.text = "No Agreement Text Specified" |
1725
52d90bbc98dc
Make it possible to specify a link to the full text
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1593
diff
changeset
|
186 |
self.url = "" |
1275
75332102f83b
Added an AgreementField widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1274
diff
changeset
|
187 |
super(AgreementField, self).__init__(*args, **kwargs) |
75332102f83b
Added an AgreementField widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1274
diff
changeset
|
188 |
|
75332102f83b
Added an AgreementField widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1274
diff
changeset
|
189 |
def render(self, name, value, attrs=None): |
2077
fd2e83a297c7
Style fixes, add missing docstring, fix some wrong calls to super classes and removal of unused imports in soc.views.helper.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
2013
diff
changeset
|
190 |
"""HTML renderer for Agreement field. |
1275
75332102f83b
Added an AgreementField widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1274
diff
changeset
|
191 |
""" |
2077
fd2e83a297c7
Style fixes, add missing docstring, fix some wrong calls to super classes and removal of unused imports in soc.views.helper.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
2013
diff
changeset
|
192 |
url_text = '<a href="%s" target="_blank">Full Text</a>' |
fd2e83a297c7
Style fixes, add missing docstring, fix some wrong calls to super classes and removal of unused imports in soc.views.helper.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
2013
diff
changeset
|
193 |
url = url_text % self.url if self.url else "" |
1275
75332102f83b
Added an AgreementField widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1274
diff
changeset
|
194 |
value = self.text.replace('\n', '<BR />') |
1725
52d90bbc98dc
Make it possible to specify a link to the full text
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1593
diff
changeset
|
195 |
result = self.HTML_CODE % {'url': url, 'text': value} |
1275
75332102f83b
Added an AgreementField widget
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1274
diff
changeset
|
196 |
return result |