【问题标题】:Limiting one Content item per Member in a Folder on Plone 4在 Plone 4 的文件夹中限制每个成员的一个内容项
【发布时间】:2011-04-29 13:47:47
【问题描述】:

我创建了一个名为“Résumé”的自定义 Archetypes 内容类型,并希望实施一项限制,即允许会员在文件夹中仅添加此类型的一项。更好的办法是将成员重定向到他或她的项目的 edit 页面,如果它已经存在于该文件夹中。

如何实施此限制并提供此额外功能?

【问题讨论】:

标签: python permissions plone zope archetypes


【解决方案1】:

可以在 eestec.base 中找到 Plone 3 的类似用例的解决方案。我们通过覆盖 createObject.cpy 并为此添加特殊检查来做到这一点。

代码位于集体 SVN 中,位于 http://dev.plone.org/collective/browser/eestec.base/trunk/eestec/base/skins/eestec_base_templates/createObject.cpy,第 20-32 行。

【讨论】:

  • 谢谢。这正是我一直在寻找的,即在内容创建部分之前进行检查的钩子,如果它已经存在,则将用户重定向到相对编辑视图。
【解决方案2】:

嗯,这是一种验证约束,所以也许可以在标题字段中添加一个验证器,实际上它并不关心标题,而是检查用户等? (我认为字段验证器传递了足够的信息来完成此操作,如果没有,覆盖 post_validate 方法或监听相应的事件应该可以工作。)

如果您尝试这样做,请记住 post_validate 在用户编辑时已被调用(即将焦点移出字段)。

【讨论】:

    【解决方案3】:

    我不知道这是否是最佳实践,但您可以在创建时从基础对象连接 def at_post_create_script,在删除时连接 manage_beforeDelete

    例如:

    from Products.ATContentTypes.lib import constraintypes
    
    class YourContentype(folder.ATFolder)
    [...]
    
        def at_post_create(self):
            origin = aq_parent(aq_inner(self))
            origin.setConstrainTypesMode(constraintypes.ENABLED)  # enable constrain types
            org_types = origin.getLocallyAllowedTypes()           # returns an immutable tuple
            new_types = [x for x in org_types if x! = self.portal_type]       # filter tuple into a list
            origin.setLocallyAllowedTypes(new_types)
    
        def manage_beforeDelete(self, item, container)          
            BaseObject.manage_beforeDelete(self, item, container)     # from baseObject
            self._v_cp_refs = None                                    # from baseObject
            origin = aq_parent(aq_inner(self))
            origin.setConstrainTypesMode(constraintypes.ENABLED)  # enable constrain types
            org_types = origin.getLocallyAllowedTypes()           # returns an immutable tuple
            new_types = [x for x in org_types].append(self.portal_type)
            origin.setLocallyAllowedTypes(new_types)
    

    注意:还有一个名为setImmediatelyAddableTypes() 的方法,您可能想探索一下。 注意二:这在内容迁移中不存在。

    【讨论】:

    • 这会将其限制为总共一个此类对象,而不是每个用户一个此类对象。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-30
    • 2021-12-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多