用于管理plone站点中plone.app.relations关系的formlib小部件。
infrae.plone.relations.form的Python项目详细描述
此扩展的目的是提供要编辑的formlib小部件 关系关系。这已经用plone 2.5和 扑通一声3。
Interface definition
我们内容的简单接口,使用自定义zope 3字段 关系:
>>> from infrae.plone.relations.schema import PloneRelation >>> from zope.interface import implements, Interface >>> class ISimpleContent(Interface): ... """Simple interface with relation.""" ... relation = PloneRelation(title=u"A relation", ... relation="relation1")
在用户界面中,zope intid用于跟踪 反对。也可以使用原型uid(检查configure.zcml 在这种情况下,所有内容都必须来自referenceable 原型类(Products.Archetypes.Referenceable)。
Widget definition
plone relation小部件是可定制的,您可以选择不同的 子窗口小部件以选择要添加到关系中的新项。这些子部件 可以接受参数。例如,在这里,您可以对 content_type。
小部件使用CustomWidgetFactory:
生成>>> from infrae.plone.relations.form import PloneRelationEditWidget >>> from infrae.plone.relations.form import PloneRelationSearchAddWidget >>> from zope.app.form import CustomWidgetFactory >>> widget_factory = CustomWidgetFactory(PloneRelationEditWidget, ... add_widget=PloneRelationSearchAddWidget, ... add_widget_args=dict(content_type='MySimpleContent'))
目前,有三个不同的小部件可以添加关系:一个 使用用户输入进行目录搜索并让select result作为对象 对于关系,一个列出对象(总是从目录中),一个 使用zope 3词汇作为输入。
infrae.plone.relations.form.utility为 构建这些小部件。
Form definition
现在,我们将使用此界面为内容制作一个简单的编辑表单:
>>> from Products.Five.formlib import formbase >>> from zope.formlib import form >>> class EditSimpleContentForm(formbase.EditForm): ... label = 'Edit form' ... description = 'Form to edit relation' ... form_fields = form.Fields(ISimpleContent) ... form_fields['relation'].custom_widget = widget_factory
很容易吗?
Real test
我们在example.py文件中添加了这段代码,表单如下 绑定到文档。我们现在加载:
>>> from Products.Five.zcml import load_string >>> load_string("""<configure xmlns="http://namespaces.zope.org/browser"> ... <page name="relation.html" ... for="infrae.plone.relations.form.example.IPloneRelationExample" ... class="infrae.plone.relations.form.example.PloneRelationEditForm" ... permission="cmf.ModifyPortalContent" /> ... </configure>""")
现在获得一个经过身份验证的浏览器:
>>> browser = self.getAuthenticatedBrowser()
首页是一个文档,所以我们应该得到我们的表单:
>>> browser.open('http://nohost/plone/front-page/relation.html') >>> 'Plone relation edit form' in browser.contents True
所以我们可以在这个add小部件中搜索plone,并且应该得到一个 响应,因为默认情况下只有一个文档包含 plone,首页本身:
>>> browser.getControl(name='form.relation.search_value').value='Plone' >>> browser.getControl(name='form.relation.search_button').click()
我们得到了一些结果:
>>> add_value = browser.getControl(name='form.relation.add_value:list') >>> add_value.getControl('Welcome to Plone').selected = True >>> browser.getControl(name='form.relation.add_button').click() >>> browser.getControl('Apply').click() >>> 'Updated on' in browser.contents True
您可以在README.EXT.txt和example.py文件中查找 更多的测试和例子。
Credits
这个小部件的第一个版本是在 比利时弗拉芒政府 <;http://www.zonderisgezonder.be>;。
您也可以通过发送您的 作者电子邮件地址上的备注或补丁(或要求SVN 访问)。