Discussion:
[Erp5-dev] own getter
Tomasz Brzezina
2008-03-05 12:11:44 UTC
Permalink
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.
--
Tomasz Brzezina
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3327 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://mail.tiolive.com/pipermail/erp5-dev/attachments/20080305/dae7eceb/attachment.bin>
Łukasz Nowak
2008-03-06 11:24:15 UTC
Permalink
Hello,

On 2008-03-05, 13:11:44
Post by Tomasz Brzezina
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' : '',
},

And Base_getTradeName is script in ZODB, which is doing all magic. That
way I've got nice getTradeName method on objects, which is
configurable using Base_getTradeName.

Regards,
Luke
--
?ukasz Nowak R&D Ventis http://www.ventis.com.pl/
tel: +48 32 768 16 85 fax: +48 32 392 10 61
``Use the Source, Luke...'' I am only craftsman.
bartek
2008-03-06 12:11:27 UTC
Permalink
Post by Łukasz Nowak
Hello,
On 2008-03-05, 13:11:44
Post by Tomasz Brzezina
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.
{
'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??

Bartek
Post by Łukasz Nowak
And Base_getTradeName is script in ZODB, which is doing all magic. That
way I've got nice getTradeName method on objects, which is
configurable using Base_getTradeName.
Regards,
Luke
--
"feelings affect productivity. (...) unhappy people write worse
software, and less of it."
Karl Fogel, "Producing Open Source Software"
Łukasz Nowak
2008-03-06 12:43:05 UTC
Permalink
Hello,

On 2008-03-06, 13:11:27
bartek <bartek at erp5.pl> wrote:

(...)
Post by bartek
Cool - I never thought about doing it like that. Why is it not on the wiki??
I thought it is evil to do it that way. But I'm brave enough to put it
on wiki:
http://www.erp5.org/HowToUsePropertySheets?action=diff&rev2=7&rev1=6

You're welcome to contribute.

By the way, I'm interested in core staff opinion about that issue and
proposed trick above.

Regards,
Luke
--
?ukasz Nowak R&D Ventis http://www.ventis.com.pl/
tel: +48 32 768 16 85 fax: +48 32 392 10 61
``Use the Source, Luke...'' I am only craftsman.
Tomasz Brzezina
2008-03-07 15:28:47 UTC
Permalink
Post by bartek
Post by Łukasz Nowak
Hello,
On 2008-03-05, 13:11:44
Post by Tomasz Brzezina
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.
{
'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' : '',
},

Or what?
--
Tomasz Brzezina

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3327 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://mail.tiolive.com/pipermail/erp5-dev/attachments/20080307/2cc5ef90/attachment.bin>
bartek
2008-03-08 09:50:34 UTC
Permalink
Post by Tomasz Brzezina
Post by bartek
Post by Łukasz Nowak
Hello,
On 2008-03-05, 13:11:44
Post by Tomasz Brzezina
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.
{
'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
{
'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
Post by Tomasz Brzezina
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"
Tomasz Brzezina
2008-03-08 10:27:16 UTC
Permalink
Post by bartek
1. Create a property the way Luke told you to, with alt_accessor_id
defining the name of the script (like Product_getCustomerNumber)
Now it looks:
class cavempPersonReference:
"""
Szczegolowe informacje o kliencie
"""

_properties = (
{'id' : 'family_number',
'description' : '',
'type' : 'string',
'mode' : 'w'},
{ 'id' : 'person_in_family_number',
'description' : '',
'type' : 'string',
'mode' : 'w' },
{ 'id' : 'customer_number',
'description' : '',
'type' : 'string',
'mode' : 'w',
'acquisition_base_category' : ('object',),
'acquisition_portal_type' : Expression('python: []'),
'acquisition_accessor_id' : 'getCustomerNumber',
'alt_accessor_id' : ('Person_getCustomerNumber',),
'acquisition_mask_value' : 1,
'default' : '',}
)
Post by bartek
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".
Fails -

Error Type: NameError
Error Value: name 'Expression' is not defined.
Post by bartek
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.
Ok. For now it would be in Custom ;D The cleaning and dividing will be
later.

Now the script is very stupid:
------------8<-----------8<------------8<----------
return "000134"
------------8<-----------8<------------8<----------
but I wonder how to access getFamilyNumber and getPersonInFamilyNumber

like this?
------------8<-----------8<------------8<----------
return context.getFamilyNumber+context.getPersonInFamilyNumber
------------8<-----------8<------------8<----------
--
T.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3327 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://mail.tiolive.com/pipermail/erp5-dev/attachments/20080308/38549b5b/attachment.bin>
bartek
2008-03-08 10:26:59 UTC
Permalink
Post by Tomasz Brzezina
Post by bartek
1. Create a property the way Luke told you to, with alt_accessor_id
defining the name of the script (like Product_getCustomerNumber)
"""
Szczegolowe informacje o kliencie
"""
_properties = (
{'id' : 'family_number',
'description' : '',
'type' : 'string',
'mode' : 'w'},
{ 'id' : 'person_in_family_number',
'description' : '',
'type' : 'string',
'mode' : 'w' },
{ 'id' : 'customer_number',
'description' : '',
'type' : 'string',
'mode' : 'w',
'acquisition_base_category' : ('object',),
'acquisition_portal_type' : Expression('python: []'),
'acquisition_accessor_id' : 'getCustomerNumber',
'alt_accessor_id' : ('Person_getCustomerNumber',),
'acquisition_mask_value' : 1,
'default' : '',}
)
Post by bartek
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".
Fails -
Error Type: NameError
Error Value: name 'Expression' is not defined.
Fish:

from Products.CMFCore.Expression import Expression

Fishing rod:

cd Products/ERP5/PropertySheet
grep Expression *
Post by Tomasz Brzezina
Post by bartek
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.
Ok. For now it would be in Custom ;D The cleaning and dividing will be
later.
------------8<-----------8<------------8<----------
return "000134"
------------8<-----------8<------------8<----------
but I wonder how to access getFamilyNumber and getPersonInFamilyNumber
like this?
------------8<-----------8<------------8<----------
return context.getFamilyNumber+context.getPersonInFamilyNumber
------------8<-----------8<------------8<----------
Yes (did you try?).

Bartek
Post by Tomasz Brzezina
------------------------------------------------------------------------
_______________________________________________
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"
Tomasz Brzezina
2008-03-08 10:58:26 UTC
Permalink
Post by bartek
from Products.CMFCore.Expression import Expression
cd Products/ERP5/PropertySheet
grep Expression *
Oh yeah! This is what I love - Fishing rod and fish. Now everything is
clean and bright.
Post by bartek
Post by Tomasz Brzezina
------------8<-----------8<------------8<----------
return "000134"
------------8<-----------8<------------8<----------
but I wonder how to access getFamilyNumber and getPersonInFamilyNumber
like this?
------------8<-----------8<------------8<----------
return context.getFamilyNumber+context.getPersonInFamilyNumber
------------8<-----------8<------------8<----------
Yes (did you try?).
YES YES YES!!!
(with small correction i forgot () after methods

BUT IT WORKS!
--
T.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3327 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://mail.tiolive.com/pipermail/erp5-dev/attachments/20080308/f5c79c12/attachment.bin>
Loading...