在plone 4.x中删除站点范围内的portlet的最佳(或最简单)方法是什么?
答案 0 :(得分:1)
这取决于。如果您有少量本地分配的portlet,我建议手动方式。如果您有本地portlet的复杂分配,则可以采用以下方式:
1-创建链接到网站根目录的browser view
2-添加这个:
from Products.Five import BrowserView
from Products.CMFCore.utils import getToolByName
from zope.component import getMultiAdapter
from plone.portlets.interfaces import IPortletManager
from plone.portlets.interfaces import IPortletAssignmentMapping
from plone.portlets.interfaces import ILocalPortletAssignable
class MyView(BrowserView):
def __call__(self):
ctool = getToolByName(self.context, 'portal_catalog')
all_brains = ctool.searchResults()
for i in all_brains:
obj = i.getObject()
if not ILocalPortletAssignable.providedBy(obj):
continue
for manager_name in ('plone.leftcolumn','plone.rightcolumn'):
manager = getUtility(IPortletManager, name=manager_name)
assignment_mapping = getMultiAdapter((obj, manager),
IPortletAssignmentMapping)
for i in assignment_mapping.keys():
del assignment_mapping['assignment_mapping']
通常检索所有对象并不是一件好事,因此您应该仔细评估内容量和本地portler。也就是说,这种方式有点激进,但它会起作用。
答案 1 :(得分:1)
我认为你写了一个小错字:
del assignment_mapping['assignment_mapping']
应该是:
del assignment_mapping[i]