datagridfield 在灵活的网络内容类型编辑器中不可见

发布于 2024-12-26 09:31:57 字数 146 浏览 0 评论 0原文

我已将collective.z3cform.datagridfield添加到我的构建中,在我的站点设置中将其视为活动状态;但是,我无法通过 Web 编辑器为灵巧内容类型添加 datagridfield 类型的字段。我缺少什么?

I've added collective.z3cform.datagridfield to my buildout, see it as active in my site settings; however, I cannot add a field of type datagridfield via the through-the-web editor for a dexterity content type. What am I missing?

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

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

发布评论

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

评论(1

静赏你的温柔 2025-01-02 09:31:57

扩展 vangheem 的答案:您可以通过提供字段工厂来提供对 Collective.z3cform.datagridfield 的支持,但这将是一个黑客。

原因是,collective.z3cform.datagridfield.row.DictRow 需要一个定义表行的模式。一旦呈现,这将成为子表单。在这种情况下,模式编辑器将需要根据(表)模式的字段类型来询问您。

根据您所追求的解决方案,您可能可以通过使用固定表架构实现字段工厂来摆脱困境,如下所示:

from five import grok
from zope import schema
import collective.z3cform.datagridfield.row
import plone.schemaeditor.interfaces
import zope.interface

# example from http://pypi.python.org/pypi/collective.z3cform.datagridfield
class ITableRowSchema(zope.interface.Interface): 
    one = schema.TextLine(title=u"One")
    two = schema.TextLine(title=u"Two")
    three = schema.TextLine(title=u"Three")

# new field factory for the zope.schema.interfaces.IObject
class DataGridFieldFactory(grok.GlobalUtility):
    grok.provides(plone.schemaeditor.interfaces.IFieldFactory)
    # this will show up in the schema editor vocabulary
    title = "DataGridField"

    def __call__(self, *args, **kwargs):
        # that's the horrid part as it will nail your field to this
        # specific schema
        kw = dict(value_type=collective.z3cform.datagridfield.row.DictRow(
            schema=ITableRowSchema))
        kwargs.update(kw)
        return zope.schema.List(*args, **kwargs)

请查看:plone.schemaeditor.fields。 py 了解有关现场工厂的更多信息。

这将为您提供适合您的内容类型的基本数据网格。缺少的是小部件,据我所知,您目前无法将其声明为小部件。

Extending vangheem's answer: You can provide support for collective.z3cform.datagridfield by providing a field factory, but it will be a hack.

Reason being is, that the collective.z3cform.datagridfield.row.DictRow expects a schema, defining the table rows. This becomes a subform once rendered. The schemaeditor in this instance would need to ask you depending on the field type also for the (table-) schema.

Depending on what solution you are after, you might be able to get away by implementing a field factory with a fixed table schema like this:

from five import grok
from zope import schema
import collective.z3cform.datagridfield.row
import plone.schemaeditor.interfaces
import zope.interface

# example from http://pypi.python.org/pypi/collective.z3cform.datagridfield
class ITableRowSchema(zope.interface.Interface): 
    one = schema.TextLine(title=u"One")
    two = schema.TextLine(title=u"Two")
    three = schema.TextLine(title=u"Three")

# new field factory for the zope.schema.interfaces.IObject
class DataGridFieldFactory(grok.GlobalUtility):
    grok.provides(plone.schemaeditor.interfaces.IFieldFactory)
    # this will show up in the schema editor vocabulary
    title = "DataGridField"

    def __call__(self, *args, **kwargs):
        # that's the horrid part as it will nail your field to this
        # specific schema
        kw = dict(value_type=collective.z3cform.datagridfield.row.DictRow(
            schema=ITableRowSchema))
        kwargs.update(kw)
        return zope.schema.List(*args, **kwargs)

Please have a look into: plone.schemaeditor.fields.py for more information about the field factory.

This will get you a basic datagrid for your content type. What's missing is the widget, which you currently can't be declared AFAIK.

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