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 collective.z3cform.keywordwidget

How to install collective.z3cform.keywordwidget

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install collective.z3cform.keywordwidget
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
1.2 Available View build log
1.1.1 Available View build log
1.1 Available View build log
1.0.1 Available View build log
Windows (64-bit)
1.2 Available View build log
1.1.1 Available View build log
1.1 Available View build log
1.0.1 Available View build log
Mac OS X (10.5+)
1.2 Available View build log
1.1.1 Available View build log
1.1 Available View build log
1.0.1 Available View build log
Linux (32-bit)
1.2 Available View build log
1.1.1 Available View build log
1.1 Available View build log
1.0.1 Available View build log
Linux (64-bit)
1.2 Available View build log
1.1.1 Available View build log
1.1 Available View build log
1.0.1 Available View build log
 
Author
License
GPL
Lastest release
version 1.2 on May 23rd, 2012

Introduction

This product adds a Keyword widget (similar to Archetypes.Widget:KeywordWidget) for plone.z3cform.

How To Use (Doc Tests):

>>> from z3c.form import testing
>>> testing.setupFormDefaults()
>>> import zope.interface
>>> import zope.schema
>>> from zope.schema.fieldproperty import FieldProperty

Use the Keywords field your field type:

>>> from collective.z3cform.keywordwidget.field import Keywords
>>> class IFoo(zope.interface.Interface):
...
...     keywords = Keywords(title=u'Keywords')
>>> class Foo(object):
...     zope.interface.implements(IFoo)
...     keywords = FieldProperty(IFoo['keywords'])
...
...     def __init__(self, keywords):
...             self.keywords = keywords
...
...     def __repr__(self):
...             return '<%s %r>' % (self.__class__.__name__, self.name)

We need to make sure that the keywords property is indexed in portal_catalog.

First, we write the indexer. The indexer is a special adapter that adapts the type of an object and provides the value of the attribute to be indexed.

>>> from plone.indexer.decorator import indexer
>>> @indexer(IFoo)
... def keywords(obj):
...     return IFoo(obj).keywords

We need to register our indexer as a named adapter, where the name corresponds to the index name. In ZCML, that may be:

<adapter name="keywords" factory=".indexers.keywords" />

For testing purpoese, we will register it directly.

>>> from zope.component import provideAdapter
>>> provideAdapter(keywords, name='keywords')

Now we add a form in which the widget will be rendered:

Specify the KeywordWidget factory ('KeywordFieldWidget') as the field's widgetFactory.

>>> from z3c.form.testing import TestRequest
>>> from z3c.form import form, field
>>> from collective.z3cform.keywordwidget.widget import KeywordFieldWidget
>>> class FooAddForm(form.AddForm):
...
...     fields = field.Fields(IFoo)
...     fields['keywords'].widgetFactory = KeywordFieldWidget
...
...     def create(self, data):
...             return Foo(**data)
...
...     def add(self, object):
...             self.context[object.id] = object
...
...     def nextURL(self):
...             return 'index.hml'

Create, update and render the form:

>>> root = app
>>> request = TestRequest()
>>> addForm = FooAddForm(root, request)
>>> addForm.update()
>>> print addForm.render()

Changelog

1.2 - unreleased
  • added option to specify index_name as field parameter. This is useful eg. for 'subjects' field which should read it's data from 'Subject' index. If not set, field name is used. [naro]
  • Added InAndOutKeywordWidget which is based on z3c.form OrderedSelectWidget [naro]
1.1.1 - 2012-02-24
  • fixed broken 1.1 release [petschki]
1.1 (2012-02-13)
  • fixed unicode errors for non-ascii keyword value support [petschki]
  • ui improved to keep newly entered categories on form errors [petschki]
1.0.1 (2009-09-29)
  • updated setup.cfg
1.0 (2009-09-29)
  • Initial release

Subscribe to package updates

Last updated May 23rd, 2012

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.