[Zope-CMF] Product properties: set and get ?
D2
borelan@wanadoo.fr
Fri, 23 May 2003 11:34:27 -0400
Well,
Chris pointed out an abuse of the properties system and he is right so
to add a property to your product, in initialise, in your product's
__init__.py module, use manage_addProperties instead of using
_setProperty directly ie:
product=getattr(context, '_ProductContext__prod')
product.manage_addProperty('new_property', 'Value', 'string')
or :
your_properties=(['property-1', 'Value_1', 'string'], ['Property_2',
12500, 'int'])
product=getattr(context, '_ProductContext__prod')
for property in your_properties:
product.manage_addProperty(property[0], property[1],
property[2])
where 'new_property' is the property's id, 'value' the property's value
and 'string' the property's type. If
ProductContext is an object created during the initialization process
to provide a context to the product.
You can find it in Products/App/ProductContext.
I didn't find another way to get the product without using
_ProductContext__prod maybe there's another one but wich one ?
I didn't find _ProductContext__prod directly but found self.__prod (in
ProductContext class) and i guessed that the __ notation had something
special.
Maybe chris would tell a Python-and-Zope-newbie, if the __ has special
effects ? I didn't find it yet...
Andre
Jean-Francois.Doyon@CCRS.NRCan.gc.ca a écrit:
> Ah! Sweet :)
>
> I ended up putting my properties on the root object since they could just as
> well be put there in my case.
>
> But since products have properties, it's good to know how to set them
> programatically and so on, and I may use this yet :)
>
> That "_ProductContext__prod" is something I'd never seen, I guess that's why
> I couldn't figure it out .. I didn't know how to "obtain" the product object
> to run setProperty on!
>
> Thanks!
> J.F.
>