Thursday, July 16, 2009

Setup zcml from plone debug prompt

Some multiadapters are not available on the plone debug prompt by default. For an example, start an instance in debug mode and type:

site = app.plone-id
from zope.component import getMultiAdapter
from zope.publisher.browser import TestRequest
request = TestRequest()
#from Products.CMFPlone.browser.interfaces import IPlone
view = getMultiAdapter((plonesite, request), name="plone")

The above works.

However, trying to get a portlet manager to render will give an error:

context = site
provider = getMultiAdapter((context, request, view), name="plone.rightcolumn")

outputs zope.component.interfaces.ComponentLookupError: ((<PloneSite at /plone-id>, <zope.publisher.browser.TestRequest instance URL=http://127.0.0.1>, <Products.Five.metaclass.Plone object at 0x6e84750>), <InterfaceClass zope.interface.Interface>, 'plone.rightcolumn')

Now try this:

from zope.app.component.site import setSite
setSite(site)

and fetch the portlet manager again:

provider = getMultiAdapter((context, request, view), name="plone.rightcolumn")
provider

This will return something like <plone.app.portlets.manager.ColumnPortletManagerRenderer object at 0xec3c110>.

No comments: