Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 47 lines (42 sloc) 1.807 kB
e5184ee first commit
Shaun Sephton authored
1 from django import forms
2 from django.conf import settings
512d34b some docs and a reverse
Shaun Sephton authored
3 from django.core.urlresolvers import reverse
e5184ee first commit
Shaun Sephton authored
4 from django.utils.safestring import mark_safe
5 from django.utils.html import conditional_escape
6 from django.utils.encoding import force_unicode
7
afff8e8 better media settings error
shaunsephton authored
8 from django.core.exceptions import ImproperlyConfigured
e5184ee first commit
Shaun Sephton authored
9 from django.forms.util import flatatt
10
11 class CKEditorWidget(forms.Textarea):
512d34b some docs and a reverse
Shaun Sephton authored
12 """
13 Widget providing CKEditor for Rich Text Editing.
14 Supports direct image uploads and embed.
15 """
e5184ee first commit
Shaun Sephton authored
16 class Media:
afff8e8 better media settings error
shaunsephton authored
17 try:
18 js = (
19 settings.CKEDITOR_MEDIA_PREFIX + 'ckeditor/ckeditor.js',
20 )
21 except AttributeError:
22 raise ImproperlyConfigured("django-ckeditor requires CKEDITOR_MEDIA_PREFIX setting.")
e267a27 @buchuki Allow selecting a toolbar type when constructing the ck-editor widget.
authored
23
24 def __init__(self, toolbar="Full", *args, **kwargs):
25 '''You can set the toolbar to Basic or Full.'''
26 self.toolbar = toolbar
27 super(CKEditorWidget, self).__init__(*args, **kwargs)
e5184ee first commit
Shaun Sephton authored
28
29 def render(self, name, value, attrs={}):
30 if value is None: value = ''
31 final_attrs = self.build_attrs(attrs, name=name)
32 return mark_safe(u'''<textarea%s>%s</textarea>
33 <script type="text/javascript">
34 CKEDITOR.replace("%s",
35 {
36 skin: "v2",
e267a27 @buchuki Allow selecting a toolbar type when constructing the ck-editor widget.
authored
37 toolbar : "%s",
e5184ee first commit
Shaun Sephton authored
38 height:"291",
39 width:"618",
512d34b some docs and a reverse
Shaun Sephton authored
40 filebrowserUploadUrl : "%s",
fd1ed4c now uses media prefix and browser
Shaun Sephton authored
41 filebrowserBrowseUrl : "%s",
42 filebrowserWindowWidth : '940',
43 filebrowserWindowHeight : '747'
e5184ee first commit
Shaun Sephton authored
44 }
45 );
e267a27 @buchuki Allow selecting a toolbar type when constructing the ck-editor widget.
authored
46 </script>''' % (flatatt(final_attrs), conditional_escape(force_unicode(value)), final_attrs['id'], self.toolbar, reverse('ckeditor_upload'), reverse('ckeditor_browse')))
Something went wrong with that request. Please try again.