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. csrf test by zukosdead 3 weeks, 5 days ago
  2. find even number by Rajeev529 9 months, 1 week ago
  3. Form field with fixed value by roam 10 months ago
  4. New Snippet! by Antoliny0919 10 months ago
  5. Add Toggle Switch Widget to Django Forms by OgliariNatan 1 year 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.