本文介绍了如何在Plone的敏捷行为中覆盖字段的默认值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们要求灵巧性内容类型必须排除导航行为,但exclude_from_nav字段的默认值为True.在行为plone.app.dexterity.behaviors.exclfromnav.IExcludeFromNavigation中,它默认为False.

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.

很明显,我可以创建自己的行为来复制IExcludeFromNavigation(默认值除外),但是我想知道是否存在基于重用IExcludeFromNavigation的方法.我们还有其他使用IExcludeFromNavigation的内容类型,我们确实希望它默认为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.

我们正在使用Plone 4.1rc3和Dexterity 1.0

We're using Plone 4.1rc3 and Dexterity 1.0

推荐答案

我正在使用plone.directives.form装饰器进行此工作.

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')

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

I also have the following in configure.zcml

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

<grok:grok package="." />

尽管马丁的回答并不能完全解决我的问题,但还是要感谢马丁.对我来说,这有点像个hack-一种更优雅的解决方案将是不错的选择.

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.

这篇关于如何在Plone的敏捷行为中覆盖字段的默认值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 17:58