限制 Plone 4 上文件夹中每个成员的一个内容项
我创建了一个名为“Résumé”的自定义 Archetypes 内容类型,并希望强制执行一项限制,允许成员在文件夹中仅添加该类型的一项。更好的方法是将成员重定向到其项目的编辑页面(如果该文件夹中已存在该项目)。
我如何强制执行此限制并提供此额外功能?
I have created a custom Archetypes content type called "Résumé" and would like to enforce a limitation that lets a Member add only one item of this type inside a folder. Even better would be redirecting the member to the edit page of his or her item, if it already exists in that folder.
How can I enforce this limitation and provide this extra functionality?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Plone 3 类似用例的解决方案可以在 eestec.base 中找到。我们通过重写 createObject.cpy 并为此添加特殊检查来做到这一点。
代码位于集体 SVN 中,位于 http://dev.plone.org/collective/browser/eestec.base/trunk/eestec/base/skins/eestec_base_templates/createObject.cpy,第 20-32 行。
A solution to a similar usecase for Plone 3 can be found in the eestec.base. We did it by overriding the createObject.cpy and adding a special check for this.
Code is in the collective SVN, at http://dev.plone.org/collective/browser/eestec.base/trunk/eestec/base/skins/eestec_base_templates/createObject.cpy, lines 20-32.
嗯,这是一种验证约束,所以也许可以在标题字段中添加一个验证器,实际上它并不关心标题,而是检查用户等? (我认为字段验证器传递了足够的信息来完成此操作,如果没有,则重写 post_validate 方法或侦听相应的事件应该可以工作。)
如果您尝试这样做,请记住,在用户编辑时已经调用了 post_validate (即将焦点移出某个字段)。
Well, it is a sort of validation constraint, so maybe add a validator to the title field that in reality does not bother about the title, but checks the user etc.? (I think a field validator is passed enough information to pull this off, if not, overriding the post_validate method or listening to the corresponding event should work.)
If you try this, bear in mind that post_validate is already called while the user is editing (ie on moving focus out of a field).
我不知道这是否是最佳实践,但您可以在创建时连接基础对象的
def at_post_create_script
,并在删除时连接manage_beforeDelete
。例如:
注意:还有一个名为
setImmediatelyAddableTypes()
的方法,您可能想探索一下。注二:这不会在内容迁移后继续存在。
I dont't know if it's best practice, but you can hook up on
def at_post_create_script
from base object on creation andmanage_beforeDelete
on delete.for example:
Note: There is also a method called
setImmediatelyAddableTypes()
, which you may want to explore.Note II: This does not survive content migration.