Adds a keyword widget(similar to archetypes.Widget:keyword widget)to Z3CForm.
collective.z3cform.keywordwidget的Python项目详细描述
简介
此产品添加了一个关键字小部件(类似于archetypes.widget:keywordwidget) 对于plone.z3form。
如何使用(文档测试):
>>> from z3c.form import testing >>> testing.setupFormDefaults() >>> import zope.interface >>> import zope.schema >>> from zope.schema.fieldproperty import FieldProperty
使用关键字字段您的字段类型:
>>> 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)
我们需要确保关键字属性在门户目录中被索引。
首先,我们编写索引器。索引器是一个特殊的适配器,它适应对象的类型 并提供要索引的属性的值。
>>> from plone.indexer.decorator import indexer >>> @indexer(IFoo) ... def keywords(obj): ... return IFoo(obj).keywords
我们需要将索引器注册为命名适配器,名称对应于 索引名。在zcml中,可能是:
<adapter name="keywords" factory=".indexers.keywords" />
为了测试目的,我们将直接注册。
>>> from zope.component import provideAdapter >>> provideAdapter(keywords, name='keywords')
现在,我们添加一个窗体,在其中将呈现小部件:
指定keywordwidget工厂(“keywordfieldwidget”)作为字段的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'
创建、更新和呈现表单:
>>> root = app >>> request = TestRequest()>>> addForm = FooAddForm(root, request) >>> addForm.update()>>> print addForm.render()
更改日志
1.3(2017-01-17)
- 固定条款列表设置。 [托马斯德斯维南]
- 添加了一个处理程序,以便可以在超模中使用。 [托马斯德斯维南]
- 使其在plone 4.3中工作:修复了 与非ascii结合。 [詹森]
- 现代化测试装置 [詹森]
1.2-2012年3月19日
- 添加了将索引名指定为字段参数的选项。这很有用 例如,对于“主题”字段,它应该从“主题”中读取数据 索引。如果未设置,则使用字段名。 [纳罗]
- 在基于z3c.form orderedselectwidget的doutkeywordwidget中添加 [纳罗]
1.1.1-2012年2月24日
- 修复了损坏的1.1版本[Petschki]
1.1(2012-02-13)
- 修正了非ascii关键字值支持的unicode错误[petschki]
- 改进了用户界面,使新输入的类别保持在表单错误[petschki]
1.0.1(2009-09-29)
- 已更新setup.cfg
1.0(2009-09-29)
- 初始版本