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.3 (2017-01-17)
Fixed terms list setup. [thomasdesvenain]
Added a handler so that it can be used in supermodels. [thomasdesvenain]
made it work in Plone 4.3: fixed a problem in vocabulary creation in combination with non-ascii. [jensens]
modernized test setup [jensens]
1.2 - 2012-03-19
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
Metadata
Release files for collective.z3cform.keywordwidget 1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| collective.z3cform.keywordwidget-1.3.tar.gz | 12.6 kB | Without provenance | Details for collective.z3cform.keywordwidget-1.3.tar.gz |
Release files / collective.z3cform.keywordwidget-1.3.tar.gz
| Download URL | collective.z3cform.keywordwidget-1.3.tar.gz |
|---|---|
| Size | 12.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e7576b3c3b513710eaf2476b2e41fa8ae71264954cfb933a9785a6f9ecf01f66
|
|
BLAKE2b-256 checksum How to use checksums |
47ff3308895d6b41d60507da440acca1817985361b95b90508100f5229b1a685
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for collective.z3cform.keywordwidget 1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.