RE: [Zope-dev] The Application object
So it's kosher then to reimport the Zope module and use app() in a constructor method, Shane? I was always afraid it would do something horrible.
-----Original Message----- From: Jeff K. Hoffman [mailto:jeff.hoffman@goingv.com] Sent: Monday, July 17, 2000 1:11 PM To: Shane Hathaway Cc: Chris McDonough; 'Jeff K. Hoffman'; zope-dev@zope.org Subject: Re: [Zope-dev] The Application object
On Mon, 17 Jul 2000, Shane Hathaway wrote:
The way to get the root application object is to open a connection to the ZODB and get the 'Application' object from the list of root objects. There is an easy shortcut:
import Zope app = Zope.app()
app now refers to a *copy* of the root Application object.
Yeehaw, that worked! I was so close. :-)
When you're done modifying it and its descendants you have to commit or abort the transaction.
[snip]
Do I need to commit or abort even if I don't make changes to the application object? The only thing I need it for is to get to the Control_Panel; I am instantiating ZClass instances in the constructor of a Python class, i.e.:
class MyClass:
def __init__(self, id, title=''): import Zope app = Zope.app()
ob = app.Control_Panel.Products.MyProduct.MyZClass('newId') ob.id = 'newId'
self._setObject('newId', ob)
# Do I need a get_transaction().abort() here? Will that not abort # the wrong transaction?
app._p_jar.close()
...
This gives you all kinds of benefits like undo and elimination of threading conflicts.
[snip]
Good stuff. Thanks, Shane.
Shane
--Jeff
--- Jeff K. Hoffman 704.849.0731 x108 Chief Technology Officer mailto:jeff.hoffman@goingv.com Going Virtual, L.L.C. http://www.goingv.com/
Chris McDonough wrote:
So it's kosher then to reimport the Zope module and use app() in a constructor method, Shane? I was always afraid it would do something horrible.
You certainly should not call reload(Zope), but the semantics of import are smart enough to only execute the module the first time it's imported. Shane
Chris McDonough wrote:
So it's kosher then to reimport the Zope module and use app() in a constructor method, Shane? I was always afraid it would do something horrible.
Now that I've read this again I realize what you're saying. You're right, what happens is you get two connections associated with one thread. The behavior of get_transaction() might not be what's expected. Someone tried something like this before in a product months ago. A bug was discovered and fixed, but the product author eventually found a better way anyway. Shane
participants (2)
-
Chris McDonough -
Shane Hathaway