[Zope-dev] Python Script

Steve Alexander steve@cat-box.net
Fri, 23 Feb 2001 12:12:40 +0000


Cyril Elkaim wrote:
 >

> This script works fine if I test it inside the test tabs of the zclass. But
> if I run it from an instance 'container.objectItems()' returns nothing. I 
> understand why but my problem is how to get access of the images from
> the instance.
> 
> What I need is something giving a reference to the zclass definition from
> one of its instance. I think I can use the DOM model and walk through until
> I find it but it should be better to have a direct access from the instance
> itself, wrong?

>From an external method, you can do

  dir(self.__class__)

or

  dir(type(self))

to get the attributes of your class.


 From a PythonScript, you can use something like

   container.Control_Panel.Products.product_name.class_name

to get a reference to the ZClass definition.

You should also be able to use this:

   container.manage_addProduct['product_name'].class_name

I suggest you make a PythonScript or external method in your ZClass 
definition called list_attributes, that returns a list of the attributes 
of the ZClass definiton. Your other methods can call that.
That way, if you change the Product of your ZClass in the future, you 
only have one thing to alter (should you choose the PythonScript).

I advise against using an external method for this, as (if you're not 
careful) it may return unwrapped objects, which is a security hazard.

--
Steve Alexander
Software Engineer
Cat-Box limited
http://www.cat-box.net