Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

Download
ActivePython
INSTALL>
pypm install z3c.formwidget.ckeditor

How to install z3c.formwidget.ckeditor

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install z3c.formwidget.ckeditor
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
1.1.0
2.0.0a1Never BuiltWhy not?
1.1.0 Available View build log
1.0.0 Available View build log
Windows (64-bit)
1.1.0
2.0.0a1Never BuiltWhy not?
1.1.0 Available View build log
1.0.0 Available View build log
Mac OS X (10.5+)
1.1.0
2.0.0a1Never BuiltWhy not?
1.1.0 Available View build log
1.0.0 Available View build log
Linux (32-bit)
1.1.0
2.0.0a1Never BuiltWhy not?
1.1.0 Available View build log
1.0.0 Available View build log
Linux (64-bit)
2.0.0a1 Available View build log
1.1.0 Available View build log
1.0.0 Available View build log
2.0.0a1 Available View build log
 
License
ZPL 2.1
Lastest release
version 2.0.0a1 on Sep 20th, 2013

This package provides a CKEditor widget for the z3c.form library. It also provides a RichText schema field, which makes the usage of CKEditor completely transparent.

Detailed Documentation

RichText Fields and CKEditor Widgets

This package a provides a new field called RichText, which is a simple extension to the default Text field. The RichText field declares that it contains HTML-markup as part of its text.

>>> from z3c.formwidget.ckeditor import richtext

So let's create a rich text field:

>>> text = richtext.RichText(__name__='text')

Let's now verify that the field provides the text and rich text schema:

>>> import zope.schema
>>> from zope.interface import verify
>>> from z3c.formwidget.ckeditor import interfaces
>>> verify.verifyObject(interfaces.IRichText, text)
True
>>> verify.verifyObject(zope.schema.interfaces.IText, text)
True

Next, a widget is provided to edit the rich text field. It uses the CKEditor.

>>> from z3c.formwidget.ckeditor import interfaces, ckeditor

The CKEditorWidget is a widget:

>>> from z3c.form.interfaces import IWidget
>>> verify.verifyClass(interfaces.ICKEditorWidget, ckeditor.CKEditorWidget)
True
>>> verify.verifyClass(IWidget, ckeditor.CKEditorWidget)
True

The widget can render an input field only by adapting a request:

>>> from z3c.form.testing import TestRequest
>>> request = TestRequest()
>>> widget = ckeditor.CKEditorWidget(request)

Such a widget provides IWidget:

>>> IWidget.providedBy(widget)
True

Let's add some meaningful generic data:

>>> widget.id = 'id'
>>> widget.name = 'name'

If we render the widget we get the HTML:

>>> widget.update()
>>> print(widget.render())
<textarea id="id" name="name" class="CKEditorWidget"></textarea>
<script type="text/javascript">CKEDITOR.replace('name', {});</script>

As you can see, initially, CK Editor is instantiated with all its defaults. This can be changed by modifying the config attribute on the widget.

If the config attribute is a string, it is interpreted as a JavaScript variable name. The variable must be declared beforehand.

>>> widget.config = 'myCKEditorConfig'
>>> widget.update()
>>> print(widget.render())
<textarea id="id" name="name" class="CKEditorWidget"></textarea>
<script type="text/javascript">CKEDITOR.replace('name', myCKEditorConfig);</script>

Alternatively, the config attribute can be a dictionary of options, which are encoded to Javascript upon render time:

>>> widget.config = '{"toolbar": "Basic", "uiColor": "#9AB8F3"}'
>>> widget.update()
>>> print(widget.render())
<textarea id="id" name="name" class="CKEditorWidget"></textarea>
<script type="text/javascript">CKEDITOR.replace('name', {"toolbar": "Basic", "uiColor": "#9AB8F3"});</script>

All other values cause a ValueError to be raised.

>>> widget.config = 3
>>> widget.update()
Traceback (most recent call last):
...
ValueError: ('Invalid config object', 3)

The field widget for the rich text field is available too of course:

>>> import zope.component
>>> from z3c.form.interfaces import IFieldWidget
>>> widget = zope.component.getMultiAdapter((text, request), IFieldWidget)
>>> widget
<CKEditorWidget 'text'>
>>> widget.update()
>>> print(widget.render())
<textarea id="text" name="text"
          class="CKEditorWidget required richtext-field"></textarea>
<script type="text/javascript">CKEDITOR.replace('text', {});</script>

You can also create CKEditor Field Widget factories on the fly using a given configuration:

>>> MinimalCKEditorWidget = ckeditor.CKEditorFieldWidgetFactory(
...     '{"toolbar": "Basic", "uiColor": "#9AB8F3"}')
>>> widget = MinimalCKEditorWidget(text, request)
>>> widget.update()
>>> print(widget.render())
<textarea id="text" name="text"
          class="CKEditorWidget required richtext-field"></textarea>
<script type="text/javascript">CKEDITOR.replace('text',
     {"toolbar": "Basic", "uiColor": "#9AB8F3"});</script>
CHANGES
2.0.0a1 (2013-03-04)
  • Added support for Python 3.3.
  • Replaced deprecated zope.interface.implements usage with equivalent zope.interface.implementer decorator.
  • Dropped support for Python 2.4 and 2.5.
1.1.0 (2011-03-02)
  • Upgraded CKEditor to 3.5.2.
  • Removed deprecation warnings.
1.0.0 (2009-11-03)
  • Initial Release

Subscribe to package updates

Last updated Sep 20th, 2013

Download Stats

Last month:1

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.