灵活地使用 Collective.z3cform.datagridfield

发布于 2024-12-18 13:32:32 字数 4323 浏览 0 评论 0原文

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

根据 collective.z3cform.datagridfield 中列出的说明,我已成功添加集体。 z3cform.datagrid Egg 添加到我的构建中的 Egg 列表中,我可以看到新的附加组件在我的网站附加组件列表中显示为“活动”。我创建了一个简单的模式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>

为了完整起见,我还包括相应的 profile/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>

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

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

I'm somewhat of a newbie to Plone and I'm attempting to use DataGridField with Dexterity. The goal is to use Plone 4.1 to publish the results of a usability study on our intranet. I've created a custom document type (called an Interaction) and I want to use datagrid for one of the fields to model a table containing two columns showing a summary of findings.

As per the instructions listed at collective.z3cform.datagridfield I've successfully added the collective.z3cform.datagrid egg to the list of eggs in my buildout and I can see the new Add-on appear as Active in my list of Add-ons for my site. I've created a simple schema Python module which describes a document showing findings from a usability study I'm documenting:

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

I've registered my new Interaction content type by adding a line to 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>

For completeness, I've also included the corresponding profiles/default/types/interaction.xml file:

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

When I go to the Add form for my Interaction custom type, I get a standard Dexterity List item Add/Remove widget rather than the datagrid table widget I've seen in the collective.z3cform.datagrid_demo examples. When I attempt to save the custom type the Dexterity list widget displays a validation error 'The system could not process the given value.'

Is there any other code I need to add? Do I need to override the Dexterity Add/EditForm view templates?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

冷血 2024-12-25 13:32:32

您正在按照记录进行操作,但它不会起作用。这是一个已知问题:

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

You're doing things as documented, but it won't work. This is a known issue:

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

祁梦 2024-12-25 13:32:32

尝试使用 Dexterity 表单提示:

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

try using Dexterity form hints:

...
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,                      
        )
萌酱 2024-12-25 13:32:32

这在 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,                      
    )

This works for me in 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,                      
    )
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文