How To remove portlets from python code

by Martin Opstad Reistadbakk last modified Mar 31, 2009 08:45 PM
This how-to will show you have to remove the standard portlets from python code. This can be useful to include in code you run from import_steps.xml. This How-To will be obsolete when plone portlets can use generic setup for portlet assignment.

Prerequisites

You should know how to use generic setup and run python code from import_steps.xml.

Code

The following code will remove the Login portlet and Recent Items portlet from the left column:

from zope.component import getUtility
from zope.component import getMultiAdapter
from plone.portlets.interfaces import IPortletManager
from plone.portlets.interfaces import IPortletAssignmentMapping

def setupPortlets(context):
    site = context.getSite()
    column = getUtility(IPortletManager, name=u'plone.leftcolumn', context=site)
    manager = getMultiAdapter((site, column,), IPortletAssignmentMapping)
    del manager["Assignment-2"] # Login portlet
    del manager["Assignment-3"] # Recent items portlet