- Author:
- Digitalxero
- Posted:
- February 1, 2008
- Language:
- Python
- Version:
- .96
- Score:
- 2 (after 2 ratings)
This is a simple FCK editor widget that can be used in newforms in place of Textarea. Obviously it requires FCKeditor and you will need to set the proper import path for that.
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 | from django.newforms.widgets import Widget
from django.utils.encoding import force_unicode
from django.utils.safestring import mark_safe
import fckeditor
class FCKeditor(Widget):
def __init__(self, attrs=None):
if attrs is not None:
self.attrs = attrs.copy()
else:
self.attrs = {}
self.__widget = fckeditor.FCKeditor("FCKeditor1")
super(FCKeditor, self).__init__(attrs)
self.setAtters(self.attrs)
def setAtters(self, attrs):
if attrs is None:
return
if 'basepath' in attrs:
self.__widget.BasePath = attrs['basepath']
if 'width' in attrs:
self.__widget.Width = attrs['width']
if 'height' in attrs:
self.__widget.Height = attrs['height']
if 'toolbar' in attrs:
self.__widget.ToolbarSet = attrs['toolbar']
def render(self, name, value, attrs=None):
if value is None: value = ''
value = force_unicode(value)
self.__widget.InstanceName = name
self.__widget.Value = value
self.setAtters(attrs)
final_attrs = self.build_attrs(attrs, name=name)
return mark_safe(self.__widget.CreateHtml())
|
More like this
- Template tag - list punctuation for a list of items by shapiromatron 11 months, 2 weeks ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 11 months, 3 weeks ago
- Serializer factory with Django Rest Framework by julio 1 year, 6 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 7 months ago
- Help text hyperlinks by sa2812 1 year, 7 months ago
Comments
Typo spotted: the method should be called "setAttrs" or the call should be "self.setAtters(self.attrs)".
#
Yup, fixed
#
Can you show a example?
#
Please login first before commenting.