如何覆盖 Plone 敏捷行为中字段的默认值?

发布于 2024-11-19 17:49:39 字数 448 浏览 7 评论 0原文

我们要求敏捷内容类型从导航行为中排除,但 exclude_from_nav 字段的默认值为 True。在 plone.app.dexterity.behaviors.exclfromnav.IExcludeFromNavigation 行为中,它默认为 False

显然,我可以创建自己的行为,复制除默认值之外的 IExcludeFromNavigation ,但我想知道是否有一种基于重用 IExcludeFromNavigation 的方法来做到这一点。我们还有其他使用 IExcludeFromNavigation 的内容类型,但我们确实希望将其默认为 False

我们使用 Plone 4.1rc3 和 Dexterity 1.0

We have a requirement for a dexterity content type to have exclude from navigation behaviour but for the exclude_from_nav field's default value to be True. In the behaviour plone.app.dexterity.behaviors.exclfromnav.IExcludeFromNavigation it defaults to False.

Obviously I could create my own behaviour that copies IExcludeFromNavigation except for the default value but I was wondering if there was a way to do this based on reusing IExcludeFromNavigation. We have other content types that use IExcludeFromNavigation where we do want it to default to False.

We're using Plone 4.1rc3 and Dexterity 1.0

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

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

发布评论

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

评论(2

淡紫姑娘! 2024-11-26 17:49:39

请参阅http://plone.org/products/dexterity/documentation/ Manual/developer-manual/advanced/defaultshttp://pypi.python.org/pypi/plone.directives.form#value-adapters,但基本上:

@form.default_value(field=IExcludeFromNavigation['exclude_from_nav'], context=IMyType)
def excludeFromNavDefaultValue(data):
    return True

干杯,
马丁

See http://plone.org/products/dexterity/documentation/manual/developer-manual/advanced/defaults and http://pypi.python.org/pypi/plone.directives.form#value-adapters, but basically:

@form.default_value(field=IExcludeFromNavigation['exclude_from_nav'], context=IMyType)
def excludeFromNavDefaultValue(data):
    return True

Cheers,
Martin

我很OK 2024-11-26 17:49:39

我使用 plone.directives.form 装饰器来完成这项工作。

我已将其添加到我的行为模块之一。

from plone.directives.form import default_value

@default_value(field = IExcludeFromNavigation['exclude_from_nav'])
def excludeFromNavDefaultValue(data):
    return data.request.URL.endswith('++add++my_item_type')

我在configure.zcml中也有以下内容

<include package="plone.directives.form" file="meta.zcml" />
<include package="plone.directives.form" />

<grok:grok package="." />

感谢Martin提供的大量线索,尽管他的回答并没有完全解决我的问题。这对我来说有点像黑客 - 一个更优雅的解决方案会很好。

I have this working using a plone.directives.form decorator.

I've added this to one of my behaviour modules.

from plone.directives.form import default_value

@default_value(field = IExcludeFromNavigation['exclude_from_nav'])
def excludeFromNavDefaultValue(data):
    return data.request.URL.endswith('++add++my_item_type')

I also have the following in configure.zcml

<include package="plone.directives.form" file="meta.zcml" />
<include package="plone.directives.form" />

<grok:grok package="." />

Thanks to Martin for the large clue although his answer didn't quite solve my problem. This feels like a bit of a hack to me - a more elegant solution would be nice.

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