[Zope3-Users] Re: Request in Zope3-Thread
Philipp von Weitershausen
philipp at weitershausen.de
Sat Aug 4 05:13:10 EDT 2007
Markus Leist wrote:
> i have created a thread in my zope3-application like the zope.sendmail.QueueProcessorThread.
>
> What i want to do: "fake" a request-context to get a local Utility
> (via Sitemanager) configured in ZODB and call some methods which will
> change some object-attributes in ZODB.
You'll have to open a new connection to the database in the thread and
get the root object from it (you'll have to give the thread a reference
to the database, which can be accessed from any persistent object thru
obj._p_jar, IIRC):
conn = db.open()
root = conn.root()
root_folder = root['Application']
Now you can traverse to the site that contains the local utilities
(unless that's the root_folder) and make the current active site
(current = for this particular thread):
from zope.app.component.hooks import setSite
site = root_folder['path']['to']['the']['site']
setSite(site)
Now do your component lookups, object modifications, etc. Don't forget
to commit the transaction at the end:
import transaction
transaction.commit()
and close the connection:
conn.close()
--
http://worldcookery.com -- Professional Zope documentation and training
More information about the Zope3-users
mailing list