[Zope-CMF] Product properties: set and get ?

D2 borelan@wanadoo.fr
Thu, 15 May 2003 11:37:02 -0400


To answer Jean-Francois's question :
I tried this in the __init__.py of a product in initialize


     product=context._ProductContext__prod
     props=({'id':''Property_1', 'value':'1', 'type':'string'},
            {'id':''Property_2', 'value':'2', 'type':'string'}
           )
     for property in props:
         product._setProperty(property['id'], property['value'],
                              property['type'])

it works!

To answer Chris,

 >>> And, more usefully, what are you actually trying to achieve here?

I have a vague idea of creating some program to automate some repetitive 
tasks and accelerate the production process by generating programs, 
pieces of programs or customization, by using description tools of my own.
So i try several things, i dive into Python, Zope.
Some of my 'work of art' are useles, some can become useful.

I have a tree-maker to wich i pass a text file with a simple description 
of my tree, the folder content, the constructors, the properties and so 
on. The tree is generated, all objects are set in their respective 
container.
That's better than repeating
object=Folder(id, title)
self._set....
self.manage_addProduct[Aaaaggghh!]
and another one and then create contained objects...Pfff!

I have a special format, (not yet completed) wich will be like this :
-Some_container-
   Object_n, class, constructor
     args
     kw
     basic_properties
     advanced_properties
     functions and methods
-Object_n-
Object_n+n, class, and so on...

The functions are created independently in a special method repository 
module.

It's like a puzzle, each piece is developed or described independently 
and the tool rebuild the puzzle following the description.

It won't be a universal tool but it will help for basic, repetitive 
silly tasks.

I don't know if it's clear or useful but it'a an answer to your question.

PS : I modify my function without exec:
def add_ClassProperty(product, module, some_class, property, value)
     object=__import__('module', globals(), globals(),
                       'Products.product')
     klass=object.some_class
     setattr(klass, property, value)
     klass._properties=klass._properties+({'id':property,
                                           'type':'string'},)


Do you feel better ?

Andre