Instantiating a ZClass in Zope from within a Python product
Is there some way of instantiating a ZClass in Zope from within a Python product? I've been trying to get access to Control_Panel.Products from within a Python product, but have so far met with no success. Is there some way to access Zope internals such as the Control Panel from within a Python product (not an external method)? I think this problem is interesting to warrant a How-To, so I'll write it up as one if I can figure it out. Thanks for any insights you can offer, Michael Bernstein.
Michael, Accessing through the control panel is supposed to work. For some reason, it doesn't lately. :-( Here's a snippet of code I'm using to grab a ZClass and instantiate it in lieu of being able to grab it from the Control Panel: def addtocart(self, distribution=0): """ """ request = self.REQUEST cart = request.AUTHENTICATED_USER.getPlace().Cart # grabbing this class is wayyyyy too hard to do. app = self.getPhysicalRoot() ut = app.unrestrictedTraverse obpath = ('Control_Panel', 'Products', 'NABSupplier', 'ZapNABAlbum', 'propertysheets', 'methods', 'ZapNABAlbumCartItemClass') klass = ut(obpath)._zclass_ # that was easy, wasn't it? item = klass(self, distribution) cart.additem(item) Michael Bernstein wrote:
Is there some way of instantiating a ZClass in Zope from within a Python product?
I've been trying to get access to Control_Panel.Products from within a Python product, but have so far met with no success.
Is there some way to access Zope internals such as the Control Panel from within a Python product (not an external method)?
I think this problem is interesting to warrant a How-To, so I'll write it up as one if I can figure it out.
Thanks for any insights you can offer,
Michael Bernstein.
_______________________________________________ Zope-Dev maillist - Zope-Dev@zope.org http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope )
-- Chris McDonough Digital Creations Publishers of Zope - http://www.zope.org
BTW, I doubt this method of grabbing a ZClass via unrestrictedTraverse should make its way into a howto because the right way to do this *SHOULD* be: klass = Control_Panel.Products..Product.Class._zclass_ a = klass() But right now, it's not. For more info on unrestrictedTraverse, see http://www.zope.org/Members/michel/Projects/Interfaces/Traversal Michael Bernstein wrote:
Is there some way of instantiating a ZClass in Zope from within a Python product?
I've been trying to get access to Control_Panel.Products from within a Python product, but have so far met with no success.
Is there some way to access Zope internals such as the Control Panel from within a Python product (not an external method)?
I think this problem is interesting to warrant a How-To, so I'll write it up as one if I can figure it out.
Thanks for any insights you can offer,
Michael Bernstein.
_______________________________________________ Zope-Dev maillist - Zope-Dev@zope.org http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope )
-- Chris McDonough Digital Creations Publishers of Zope - http://www.zope.org
For more info on unrestrictedTraverse, see http://www.zope.org/Members/michel/Projects/Interfaces/Traversal
Is this released yet, or only in cvs? --jfarr
Geez... good question. let's see... Damn. Sorry for misleading everybody! This is only in CVS. Jonothan Farr wrote:
For more info on unrestrictedTraverse, see http://www.zope.org/Members/michel/Projects/Interfaces/Traversal
Is this released yet, or only in cvs?
--jfarr
-- Chris McDonough Digital Creations Publishers of Zope - http://www.zope.org
Chris McDonough wrote:
Damn. Sorry for misleading everybody! This is only in CVS.
Ok, So is there any way (in Zope 2.1.6) to instantiate a ZClass in Zope from within a Python product by accessing self.Control_Panel.Products, or by any other means? Is there some sort of 'Chinese Wall' between the two ways of building applications, or is this a bug? Michael Bernstein.
This is a bug. I suppose I should put this in the collector. Bleah. I found an (unsupported) way of getting at them through the root object's _product_zclasses attribute (which holds a tuple containing mappings describing zclasses). This way of getting at Zclasses is not recommended, as it's an implementation detail and not an interface and will almost certainly change. But... import Zope app = Zope.app() myzclassstuff = app._product_zclasses Then poke through the myzclassstuff... meta_class is the member of the mapping that you want to look at that contains the actual class. I found this by accident, and when I asked Jim about it I got a sidelong glance, so you should *definitely* not base anything permanent on this method of grabbing zclass instances. Michael Bernstein wrote:
Chris McDonough wrote:
Damn. Sorry for misleading everybody! This is only in CVS.
Ok, So is there any way (in Zope 2.1.6) to instantiate a ZClass in Zope from within a Python product by accessing self.Control_Panel.Products, or by any other means?
Is there some sort of 'Chinese Wall' between the two ways of building applications, or is this a bug?
Michael Bernstein.
-- Chris McDonough Digital Creations Publishers of Zope - http://www.zope.org
----- Original Message ----- From: "Chris McDonough" <chrism@digicool.com> To: "Michael Bernstein" <mbernstein@profitscape.com> Cc: <zope-dev@zope.org> Sent: Monday, May 08, 2000 6:21 PM Subject: Re: [Zope-dev] Instantiating a ZClass in Zope from within a Python product
BTW, I doubt this method of grabbing a ZClass via unrestrictedTraverse should make its way into a howto because the right way to do this *SHOULD* be:
klass = Control_Panel.Products..Product.Class._zclass_ a = klass()
just to make sure I'm not off my rocker, there should be a "self." in front of Control_Panel, right? Kevin
yes... you're not off your rocker :-) Kevin Dangoor wrote:
klass = Control_Panel.Products..Product.Class._zclass_ a = klass()
just to make sure I'm not off my rocker, there should be a "self." in front of Control_Panel, right?
Kevin
-- Chris McDonough Digital Creations Publishers of Zope - http://www.zope.org
participants (4)
-
Chris McDonough -
Jonothan Farr -
Kevin Dangoor -
Michael Bernstein