【问题标题】:Using collective.z3cform.datagridfield with Dexterity使用带敏捷的collective.z3cform.datagridfield
【发布时间】:2011-11-28 19:20:37
【问题描述】:

我是 Plone 的新手,我正在尝试将 DataGridField 与 Dexterity 一起使用。目标是使用 Plone 4.1 在我们的 Intranet 上发布可用性研究的结果。我创建了一个自定义文档类型(称为交互),并且我想对其中一个字段使用数据网格来对包含两列显示结果摘要的表格进行建模。

按照collective.z3cform.datagridfield 中列出的说明,我已成功将collective.z3cform.datagrid 鸡蛋添加到我的构建中的鸡蛋列表中,并且我可以看到新插件在我的插件列表中显示为活动-我的网站。我创建了一个简单的模式 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/types.xml 添加一行来注册我的新交互内容类型:

<?xml version="1.0"?>
<object meta_type="Plone Types Tool" name="portal_types">
<property name="title">Controls the available content types in your portal</property>
<object meta_type="Dexterity FTI" name="interaction" />
<!-- -*- extra stuff goes here -*- -->
</object>

为了完整起见,我还包含了相应的配置文件/default/types/interaction.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>

当我转到我的交互自定义类型的添加表单时,我得到一个标准的敏捷列表项添加/删除小部件,而不是我在集体.z3cform.datagrid_demo 示例中看到的数据网格表小部件。当我尝试保存自定义类型时,敏捷列表小部件显示验证错误“系统无法处理给定值。”

我还需要添加其他代码吗?我是否需要覆盖 Dexterity Add/EditForm 视图模板?

【问题讨论】:

  • 您能否也添加您的敏捷内容项目类定义,以便我们查看它?
  • 我对 Plone/Dexterity 术语还是有些陌生。内容项类定义是配置文件/默认/类型中的 XML 文件吗?我已经更新了我的帖子,现在包括这个。非常感谢。
  • 你有没有像 在你的 configure.zcml?否则,将找不到自定义编辑表单。编辑表单上的“字段”属性也可能被 plone.autoform 机制覆盖,这通常会根据内容类型的架构配置要显示的字段。
  • 是的,我有 在我的 configure.zcml 中。我也尝试过添加自定义编辑表单模板,但也没有被采纳。名称是view.pt 旁边的interaction_templates/edit.pt。这是覆盖自动成型机制的正确方法吗?

标签: python plone dexterity z3c.form


【解决方案1】:

您正在按照文档中的方式进行操作,但它不起作用。这是一个已知问题:

http://code.google.com/p/dexterity/issues/detail?id=246

【讨论】:

    【解决方案2】:

    尝试使用敏捷表单提示:

    ...
    from zope import schema
    from zope.interface import Interface
    
    from plone.directives import form
    
    from collective.z3cform.datagridfield import DataGridFieldFactory, DictRow
    
    from plonetheme.mytheme import InteractionMessageFactory as _
    ...
    
    
    class IFindingRow(Interface):
        summary = schema.TextLine(title=_(u'Summary'), 
                                  required=False)
        percentage = schema.TextLine(title=_(u'Percentage'), 
                                     required=False)
    
    
    class IInteraction(form.Schema):
    
        ...
    
        form.widget(findings=DataGridFieldFactory)
        findings= schema.List(
                title=_(u"Overview of findings"),
                value_type=DictRow(title=_(u"Finding"), 
                                   schema=IFindingRow),
                required=False,                      
            )
    

    【讨论】:

    • 这将显示网格,但不会保存在网格中输入的值。
    【解决方案3】:

    这在 Plone 5.0.4 中适用于我

    from zope import schema 
    from zope.interface import Interface
    from plone.supermodel import model
    from plone.autoform import directives
    from collective.z3cform.datagridfield import DataGridFieldFactory, DictRow
    from plonetheme.mytheme import InteractionMessageFactory as _
    
    class IFindingRow(Interface):
        summary = schema.TextLine(title=_(u'Summary'), 
                              required=False)
        percentage = schema.TextLine(title=_(u'Percentage'), 
                                 required=False)
    
    
    class IInteraction(model.Schema):
        directives.widget(findings=DataGridFieldFactory)
        findings= schema.List(
            title=_(u"Overview of findings"),
            value_type=DictRow(title=_(u"Finding"), 
                               schema=IFindingRow),
            required=False,                      
        )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-06-04
      • 2010-10-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多