[Zope-dev] Instantiating a ZClass in Zope from within a Python product

Chris McDonough chrism@digicool.com
Mon, 08 May 2000 18:18:32 -0400


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