为了防止portlet获取并保持添加portlert的可能性,您可以添加事件侦听器来创建自动阻止获取的内容。
像这样:
<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 manage view
编辑19/08/2011启发:包含的修补程序的建议由@will在我未经测试的代码...所以现在是测试
谢谢!这正是我想要做的,它阻止了现有的portlet,同时保留了用户将来分配它们的能力。我非常想要在portlets.xml中做一些事情,这是订阅者没有想到的。 – Will
对于后代,应该对上述代码进行一些修改,以使其发挥作用。在ZCML中,'factory'属性应该是'handler',管理者名称需要用'getUtility()'与它们各自的'IPortletManager'管理器匹配。 – Will
@请问您能否将此答案标记为您问题的答案? – toutpt