Plone内容类型特定的Portlet分配
我正在为Plone 4开发一种内容类型,我想阻止所有用户、组和上下文的portlet,这些portlet可能会从它的父对象那里继承过来。现在我对文档感到非常困惑——在portlets.xml中,<blacklist/>
似乎只处理特定路径的阻止。<assignment/>
看起来像是我想要的,但又太具体了——我不想为我的内容类型管理所有可能的portlet的分配。
我发现有一些提示,提到可以定制一个特定于内容类型的ILeftColumn和IRightColumn portlet管理器,但我找不到好的例子。有没有人能给我一些提示或建议?我感觉我可能漏掉了一些非常简单的东西。
2 个回答
1
在你的网站上,通过站点设置(控制面板)去做这个分配,路径是:站点设置 -> 类型 -> “管理分配给这个内容类型的端口小部件”。
然后通过ZMI导出配置,路径是:portal_setup -> 导出标签 -> 选择“端口小部件” -> 在底部点击“导出”。
提取types/YourType.xml文件,把相关的部分复制到你包的profiles/default/types/YourType.xml里。
6
为了防止获取portlet(小部件),同时保持可以添加portlet的可能性,你可以在创建内容时添加一个事件监听器,这样就可以自动阻止获取。
像这样:
<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管理视图
编辑于2011年8月19日:根据@will的建议对我未测试的代码进行了修正……现在已经测试过了