[Zope3-Users] Get a site

Christian Theune ct at gocept.com
Mon Jan 22 02:32:21 EST 2007


Hi,

Am Sonntag, den 21.01.2007, 14:44 +0100 schrieb Florian Lindner:
> Hello,
> I am in a function that has no context and want to set a site.
> The function is called periodically from a scheduler:
> 
> from scheduler import loop
> 
> def onStartup(event):
>     refresher = loop.LoopTask(releaseRefreshEvent, interval=60)
> 
> In this function I need to call getUtilitiesFor which needs a site set but I 
> don't know how to get a site:
> 
> (Pdb)  from zope.app.component import hooks
> (Pdb) from zope.app.zapi import *
> 
> (Pdb) hooks.setSite(getSiteManager())
> *** AttributeError: 'BaseGlobalComponents' object has no 
> attribute 'getSiteManager'
> 
> (Pdb) hooks.setSite(getGlobalSiteManager())
> *** AttributeError: 'BaseGlobalComponents' object has no 
> attribute 'getSiteManager'

You don't set the site managers as a site, but the objects that are
sites have site managers (or "component registries") attached to them.

Also, the global registry is always "active", without settinga site.

> Just getting the root object (which AFAIK always is a site) would be ok. Or 
> the object of static path.

You'd have to open a connection to the database, get the root object and
use that with setSite(). I don't have the complete spelling for that in
my head though. If this is code that runs within Zope 3, then you might
not want to talk to the database directly anyway because of the
automatic transaction management.

Christian

-- 
gocept gmbh & co. kg - forsterstraße 29 - 06112 halle/saale - germany
www.gocept.com - ct at gocept.com - phone +49 345 122 9889 7 -
fax +49 345 122 9889 1 - zope and plone consulting and development
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Dies ist ein digital signierter Nachrichtenteil
Url : http://mail.zope.org/pipermail/zope3-users/attachments/20070122/c05c9e9e/attachment.bin


More information about the Zope3-users mailing list