[Erp5-dev] own getter

bartek bartek at erp5.pl
Sat Mar 8 10:50:34 CET 2008


Tomasz Brzezina wrote:
> bartek pisze:
>> Łukasz Nowak wrote:
>>> Hello,
>>>
>>> On 2008-03-05, 13:11:44
>>> Tomasz Brzezina <tomasz at brzezina.pl> wrote:
>>>
>>>> I made two new properties in PropertySheet/cavempPersonProperty.py
>>>>
>>>> and after adding it in right portal_types - everything works
>>>> perfectly. But now I need an concatenation of those two which i need
>>>> in listbox -
>>>>
>>>> so I have to made a getter which returns a concatenation. The
>>>> question is: WHERE should I wrote the code. I think the 
>>>> PropertySheet/cavempPersonProperty.py is the wrong place - but I have
>>>> no idea where is the right place. Of course I can write it in
>>>> anywhere patching the existing code, but this will broke updating. So
>>>> where should I put my code.
>>> I hit same problem some time ago - I needed to made my own accessor.
>>> What I done is getter in ZODB, and my property definition looks like:
>>>
>>>     {
>>>       'id'          : 'trade_name',
>>>       'description' : 'Trade name of resource',
>>>       'type'        : 'string',
>>>       'mode'        : 'w',
>>>       'acquisition_base_category' : ('object',),
>>>       'acquisition_portal_type' : Expression('python: []'),
>>>       'acquisition_accessor_id' : 'getTradeName',
>>>       'alt_accessor_id' : ('Base_getTradeName',),
>>>       'acquisition_mask_value' : 1,
>>>       'default'     : '',
>>>     },
>>>
>>
>> Cool - I never thought about doing it like that. Why is it not on the 
>> wiki??
> well - can somebody explain sth more?
> SHould I make a folder in custom called my_python_scripts and inside 
> make getCustomerNumber python script
> 
> and add property:
>     {
>        'id'          : 'customer_number',
>        'description' : 'customer_number prepared by joining two other 
> properties',
>        'type'        : 'string',
>        'mode'        : 'w',
>        'acquisition_base_category' : ('object',),
>        'acquisition_portal_type' : Expression('python: []'),
>        'acquisition_accessor_id' : 'getCustomerNumber',
>        'alt_accessor_id' : ('my_python_scripts',),
>        'acquisition_mask_value' : 1,
>        'default'     : '',
>      },
> 

No.

You should:

1. Create a property the way Luke told you to, with alt_accessor_id 
defining the name of the script (like Product_getCustomerNumber)

Reload the property sheet, make sure it is attached to the portal type. 
Once you do this, every object of this portal type (e.g.Product) already 
has an auto-generated accessor "getCustomerNumber".

2. Create a script Product_getCustomerNumber in "custom" skin or in any 
other skin which is in the skin queue (read CMF documentation for 
details). Which one you choose doesn't really matter from technical 
point of view, it is a matter of convention - e.g. if this relates to a 
Product portal type you should create a skin like "tomek_pdm", being an 
overay to erp5_pdm, and put it there.

Bartek



> Or what?
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Erp5-dev mailing list
> Erp5-dev at erp5.org
> http://mail.nexedi.com/mailman/listinfo/erp5-dev


-- 
"feelings affect productivity. (...) unhappy people write worse 
software, and less of it."
Karl Fogel, "Producing Open Source Software"



More information about the Erp5-dev mailing list