Login

FCKWidget for NewForms

Author:
Digitalxero
Posted:
February 1, 2008
Language:
Python
Version:
.96
Tags:
newforms rich-text-editor wisiwig
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. Overriding Third-party Admin by mattdw 6 years, 5 months ago
  2. newforms-admin edit callback-url hook by myers 6 years, 11 months ago
  3. YUI editor for flatpages inside admin interface by nnrcschmdt 6 years, 11 months ago
  4. Generic Views for newforms by jnievas 7 years, 1 month ago
  5. Global custom permissions (no model association) by miracle2k 7 years, 7 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.