开发者

Delete all portlets site-wide in Plone

What's th开发者_如何学JAVAe best (or simplest) way to delete portlets site-wide in plone 4.x?


It depends. If you have a small amount of local assigned portlets I suggest the manual way. If you have a complex assignment of local portlets you could take this way:

1- create a browser view linked to the site root

2- add this:

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']

Usually retrieving all objects is not a good thing, so you should evaluate carefully the amount of contents and local portlers. That said, this way is a bit aggressive but it will do the job.


I think you made a small typo:

del assignment_mapping['assignment_mapping']

should be:

del assignment_mapping[i]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜