跳转到主要内容

为z3cform添加一个关键词小部件(类似于Archetypes.Widget:KeywordWidget)。

项目描述

简介

此产品为plone.z3cform添加了一个关键词小部件(类似于Archetypes.Widget:KeywordWidget)。

使用方法(文档测试)

>>> 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)

我们需要确保关键词属性在portal_catalog中已索引。

首先,我们编写索引器。索引器是一种特殊适配器,它适配对象的类型并提供了要索引的属性的值。

>>> 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')

现在我们添加一个表单,其中将渲染小部件

指定关键字小部件工厂('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)

  • 固定术语列表设置。[thomasdesvenain]

  • 添加了一个处理器,使其可以在超级模型中使用。[thomasdesvenain]

  • 使其在Plone 4.3中工作:修复了与非ASCII字符组合的词汇创建问题。[jensens]

  • 现代化测试设置[jensens]

1.2 - 2012-03-19

  • 添加了指定index_name作为字段参数的选项。这对于例如'subjects'字段很有用,该字段应从'Subject'索引读取其数据。如果未设置,则使用字段名称。[naro]

  • 添加了基于z3c.form OrderedSelectWidget的InAndOutKeywordWidget。[naro]

1.1.1 - 2012-02-24

  • 修复了1.1版本中的损坏问题[petschki]

1.1 (2012-02-13)

  • 修复了非ASCII关键字值支持的Unicode错误[petschki]

  • UI改进,以在表单错误时保留新输入的分类。[petschki]

1.0.1 (2009-09-29)

  • 更新了setup.cfg

1.0 (2009-09-29)

  • 初始发布

项目详情


下载文件

下载适用于您的平台的文件。如果您不确定要选择哪个,请了解更多关于安装包的信息。

源分发

collective.z3cform.keywordwidget-1.3.tar.gz (12.6 kB 查看哈希)

上传时间

由以下机构支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面