-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwidgets.py
50 lines (44 loc) · 1.96 KB
/
widgets.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from django import forms
from django.conf import settings
from django.utils.safestring import mark_safe
class WYMEditor(forms.Textarea):
class Media:
js = (
'/media_root/jquery/jquery.js',
'/media_root/wymeditor/jquery.wymeditor.js',
'/media_root/wymeditor/plugins/jquery.wymeditor.filebrowser.js',
)
def __init__(self, language=None, attrs=None):
self.language = language or settings.LANGUAGE_CODE[:2]
self.attrs = {'class': 'wymeditor'}
if attrs:
self.attrs.update(attrs)
super(WYMEditor, self).__init__(attrs)
def render(self, name, value, attrs=None):
rendered = super(WYMEditor, self).render(name, value, attrs)
return rendered + mark_safe(u'''<script type="text/javascript">
jQuery('#id_%s').wymeditor({
updateSelector: '.submit-row input[type=submit]',
updateEvent: 'click',
lang: '%s',
logoHtml: '',
postInitDialog: wymeditor_filebrowser,
});
</script>''' % (name, self.language))
class BasicWYMEditor(WYMEditor):
def render(self, name, value, attrs=None):
rendered = super(WYMEditor, self).render(name, value, attrs)
return rendered + mark_safe(u'''<script type="text/javascript">
jQuery('#id_%s').wymeditor({
updateSelector: '.submit-row input[type=submit]',
updateEvent: 'click',
lang: '%s',
dialogFeatures: 'menubar=no,titlebar=no,toolbar=no',
logoHtml: '',
toolsItems: [
{'name': 'Bold', 'title': 'Strong', 'css': 'wym_tools_strong'},
{'name': 'Italic', 'title': 'Emphasis', 'css': 'wym_tools_emphasis'},
{'name': 'ToggleHtml', 'title': 'HTML', 'css': 'wym_tools_html'}
]
});
</script>''' % (name, self.language))