[z3-five] Plone Tool without acquisition
Philipp von Weitershausen
philipp at weitershausen.de
Thu Feb 8 12:00:54 CET 2007
On 8 Feb 2007, at 11:06 , yuppie wrote:
> Philipp von Weitershausen wrote:
>> Dennis Schulz wrote:
>>>> - The right way to solve your problem would be using a local
>>>> site manager. Even if your tools are not registered as
>>>> utilities, you can get hold of the site root and therefor of the
>>>> tool without using acquisition. Plone 3.0 might give you some
>>>> hints how to set this up.
>>> I am not familiar with the Plone 3 code.
>>> Can anyone point me to an example where I can see how to set up
>>> a local site manager?
>>>
>>> I registered
>>>
>>> <five:localsite
>>> class="Products.CMFPlone.Portal.PloneSite" />
>>> What is the easiest way to get hold of the site root so I can
>>> use the Plone tool without acquisition?
>> Why would you want to get hold of the site root? Assuming that the
>> CMF tools are registered as local utilities, you should simply be
>> able to say:
>> from zope.component import getUtility
>> from Products.CMFPlone.interfaces import IPloneTool # verify this
>> plone_tool = getUtility(IPloneTool)
>> Zope will automatically figure out that where it should get that
>> tool from (because it traversed over the site).
>
> You missed the start of this thread.
Possibly. As far as I'm concerned, the thread started with Dennis's
email, though, didn't it?
> We were not talking about a clean solution that requires properly
> registered and acquisition wrapped tools.
>
> We were talking about a hack for using tools in vocabularies
> without acquisition context. Right now, in Zope 2.9, without the
> not yet existing five.localsitemanager.
Gotcha.
> In Zope 2.10 I can use zope.app.component.hooks.getSite() to get
> the acquisition wrapped site. Don't know what needs to be set up in
> Zope 2.9 to have this available.
Well, the canonical way in both Zope 2.10 and 2.9 is to make your
plone site an ISite. However, in Zope 2.10 that's a lot cleaner and
nicer (though I still want to make it even nicer for Zope 2.11).
In Five 1.3/1.4 on Zope 2.9, this can be done using the
<five:localsite class="...PloneSite" /> directive. This will add the
IPossibleSite interface to the PloneSite class. That means plone
sites *can* be turned into ISites, you just need to perform the
actual operation on each individual object. To do that, you need to
call Products.Five.site.localsite.enableLocalSiteHook(the_plone_site)
on the plone site object. This will install a traversal hook so the
site is remembered during traversal.
As said, don't use this code past Zope 2.9.
More information about the z3-five
mailing list