[Zope3-Users] Re: getUtilitiesFor without context

Philipp von Weitershausen philipp at weitershausen.de
Wed Jan 10 18:18:02 EST 2007


Florian Lindner wrote:
> Hello,
> I have some local utilites registered. Now I try to call them from a function 
> that don't have a context:
> 
>     utils = getUtilitiesFor(INewsfeed)
>     for i in utils:
>         print "Utility called:", i.__name__
>         i.sendNotification()
> 
> but that always deliver no utilities. How do get them without supplying a 
> context. (the function is called regularly from a scheduler object, therefore 
> it needs to be static)

You need to have traversed over the site that contains the local 
utilities first, before they can be found. If this function is called 
outside a request context, use 
zope.app.component.hooks.setSite(site_obj) to manually set the site.


-- 
http://worldcookery.com -- Professional Zope documentation and training
2nd edition of Web Component Development with Zope 3 is now shipping!



More information about the Zope3-users mailing list