Login

FCKWidget for NewForms

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

  1. Template tag - list punctuation for a list of items by shapiromatron 2 months, 2 weeks ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 2 months, 3 weeks ago
  3. Serializer factory with Django Rest Framework by julio 9 months, 3 weeks ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 10 months, 1 week ago
  5. Help text hyperlinks by sa2812 11 months ago

Comments

zgoda (on February 2, 2008):

Typo spotted: the method should be called "setAttrs" or the call should be "self.setAtters(self.attrs)".

#

Digitalxero (on February 3, 2008):

Yup, fixed

#

denilton (on October 30, 2008):

Can you show a example?

#

Please login first before commenting.