我有点像个新手,我正在尝试灵活地使用DataGridField。我们的目标是使用plone4.1在我们的内部网上发布可用性研究的结果。我已经创建了一个定制的文档类型(称为交互),我想对其中一个字段使用datagrid来建模一个包含两个列的表,该表显示了结果的摘要。在
按照collective.z3cform.datagridfield中列出的说明,我成功地添加了collective.z3cform.datagrid在我的buildout中,我可以看到新的附加组件在我的站点的附加组件列表中显示为活动的。我创建了一个简单的模式Python模块,该模块描述了一个文档,其中显示了我正在记录的可用性研究的结果:
from five import grok
from zope import schema
from zope import interface
from plone.directives import form
from plonetheme.mytheme import InteractionMessageFactory as _
from plone.app.textfield import RichText
from z3c.form import field, button
from Products.CMFCore.interfaces import IFolderish
from collective.z3cform.datagridfield import DataGridFieldFactory, DictRow
class IFinding(interface.Interface):
summary = schema.TextLine(title=_(u"Summary"))
percentage = schema.TextLine(title=_(u"Percentage"))
class IInteraction(form.Schema):
findings = schema.List(
title=_(u"Overview of findings"),
required=False,
value_type=DictRow(
title=_(u"Finding"),
schema=IFinding
)
)
class EditForm(form.EditForm):
grok.context(IInteraction)
grok.require('zope2.View')
fields = field.Fields(IInteraction)
fields['findings'].widgetFactory = DataGridFieldFactory
我通过在profiles/default中添加一行来注册新的交互内容类型/类型.xml公司名称:
^{pr2}$为了完整起见,我还包括了相应的profiles/default/types/交互.xml文件:
<?xml version="1.0"?>
<object name="interaction" meta_type="Dexterity FTI"
xmlns:i18n="http://xml.zope.org/namespaces/i18n">
<property name="title">Interaction</property>
<property name="description">An item in the interactions dictionary</property>
<property name="icon_expr">string:${portal_url}/document_icon.png</property>
<property name="factory">interaction</property>
<property name="link_target"></property>
<property name="immediate_view">view</property>
<property name="global_allow">True</property>
<property name="filter_content_types">True</property>
<property name="allowed_content_types"/>
<property name="allow_discussion">False</property>
<property name="default_view">view</property>
<property name="view_methods">
<element value="view"/>
</property>
<property name="default_view_fallback">False</property>
<property name="add_permission">cmf.AddPortalContent</property>
<property name="klass">plone.dexterity.content.Item</property>
<property name="behaviors">
<element value="plone.app.dexterity.behaviors.metadata.IDublinCore"/>
<element value="plone.app.content.interfaces.INameFromTitle"/>
<element value="collective.flowplayer.behaviors.IFlowplayerFile"/>
</property>
<property name="schema">plonetheme.mytheme.interaction.IInteraction</property>
<property name="model_file"></property>
<alias from="(Default)" to="(dynamic view)"/>
<alias from="edit" to="@@edit"/>
<alias from="sharing" to="@@sharing"/>
<alias from="view" to="(selected layout)"/>
<action title="View" action_id="view" category="object" condition_expr=""
icon_expr="" link_target="" url_expr="string:${object_url}"
visible="True">
<permission value="View"/>
</action>
<action title="Edit" action_id="edit" category="object" condition_expr=""
icon_expr="" link_target="" url_expr="string:${object_url}/edit"
visible="True">
<permission value="Modify portal content"/>
</action>
</object>
当我转到交互自定义类型的Add表单时,我得到了一个标准的Dexterity列表项Add/Remove小部件,而不是collective.z3中看到的datagrid表小部件cform.datagrid_演示例子。当我试图保存自定义类型时,Dexterity list小部件显示一个验证错误“系统无法处理给定值”
我还需要添加其他代码吗?是否需要覆盖Dexterity添加/编辑表单视图模板?在
这对我在Plone 5.0.4中很有用
尝试使用灵巧形式提示:
你做的事情是有记录的,但这行不通。这是一个已知的问题:
http://code.google.com/p/dexterity/issues/detail?id=246
相关问题 更多 >
编程相关推荐