我正在为 Plone 4 开发一个内容类型,我想阻止它可能从其父对象继承的所有用户、组和上下文 portlet。此时我对文档感到非常困惑——在 portlets.xml 中,<blacklist/>
似乎只解决特定于路径的阻塞。 <assignment/>
似乎是我想要的,但它似乎太具体了——我不想管理我的内容类型上所有可能的 portlet 的分配。
有迹象表明,我发现自定义特定于内容类型的 ILeftColumn 和 IRightColumn portlet 管理器,但我找不到任何好的示例。有没有人有任何提示或建议?我觉得我错过了一些非常简单的东西。
最佳答案
为了防止 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 建议的修复...所以现在已经过测试
关于python - Plone 内容类型特定的 Portlet 分配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7432317/