克隆内容类型特定的Portlet分配 [英] Plone Content Type-Specific Portlet Assignment

查看:90
本文介绍了克隆内容类型特定的Portlet分配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为Plone 4开发一种内容类型,我想阻止它可能从其父对象继承的所有用户,组和上下文portlet.此时,我对文档完全感到困惑–在portlets.xml中,<blacklist/>似乎仅解决特定于路径的阻塞. <assignment/>似乎是我想要的,但是似乎太具体了–我不想管理内容类型上所有可能的portlet的分配.

I'm developing a content type for Plone 4, and I'd like to block all user, group, and context portlets it may inherit from its parent object. I'm thoroughly confused by the documentation at this point–in portlets.xml, <blacklist/> only seems to address path-specific blocking. <assignment/> seems like what I want, but it seems too specific–I don't want to manage the assignment for all possible portlets on my content type.

有一些提示,我发现自定义特定于内容类型的ILeftColumn和IRightColumn portlet管理器,但是我找不到任何好的示例.有人有任何提示或建议吗?我感觉好像缺少了一些简单的东西.

There are hints that I've found that customizing an ILeftColumn and IRightColumn portlet manager specific to the content type, but I can't find any good examples. Does anyone have any hints or suggestions? I feel like I'm missing something dead simple.

推荐答案

为防止portlet收购并保持添加portlert的可能性,您可以在创建自动阻止该收购的内容时添加事件侦听器.

to prevent the portlet aquisition and maintain the possibility of adding portlert you can add an event listener on the creation of your contents that auto blocks the aquisition.

赞:

    <subscriber
        for="my.package.interfaces.IMyContent
             zope.app.container.interfaces.IObjectAddedEvent"                 
handler=".subscribers.blockPortletsUpponMyContentCreation"
                  />

然后执行以下操作:

from zope.component import getMultiAdapter, getUtility
from plone.portlets.interfaces import IPortletManager
from plone.portlets.interfaces import ILocalPortletAssignmentManager
from plone.portlets.constants import USER_CATEGORY
from plone.portlets.constants import GROUP_CATEGORY
from plone.portlets.constants import CONTENT_TYPE_CATEGORY
from plone.portlets.constants import CONTEXT_CATEGORY

def blockPortletsUpponMyContentCreation(mycontent, event):
    for manager_name in ('plone.leftcolumn','plone.rightcolumn'):
        manager = getUtility(IPortletManager, name=manager_name)
        assignable = getMultiAdapter((mycontent, manager,), ILocalPortletAssignmentManager)
        for category in (GROUP_CATEGORY, CONTENT_TYPE_CATEGORY,CONTEXT_CATEGORY,USER_CATEGORY):
            assignable.setBlacklistStatus(category, 1)

注意:此代码的灵感来自 plone.app.portlet管理视图

Note: this code is inspired by the plone.app.portlet manage view

2011年8月19日在我未经测试的代码中包含了@will建议的修复程序...因此现在已通过测试

Edit 19/08/2011: included fixes as suggested by @will in my untested code...so now is tested

这篇关于克隆内容类型特定的Portlet分配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆