Discussion:
[Erp5-dev] getter for acquired property
Bartłomiej Górny
2006-01-02 21:00:08 UTC
Permalink
Hi

Another question - best described in an example:

In the "Organisation" module there is an Organisation class which has
and Organisation property sheet, which says:

{'id' : 'social_capital_currency_id',
'type' : 'string',
'portal_type' : 'Currency',
'acquisition_base_category' : ('price_currency'),
'acquisition_portal_type' : ('Currency'),
'acquisition_copy_value' : 0,
'acquisition_mask_value' : 1,
'acquisition_sync_value' :0,
'acquisition_accessor_id' : 'getId',
'mode' : 'w' }

(and the same for _title).

After editing the object (with the stock form), Base_viewDict shows that
social_capital_currency='currency_module/PLN'

The question is, how to get it by an appropriate getter?
getSocialCapitalCurrencyId and getSocialCapitalCurrencyTitle exist but
return nothing, getSocialCapitalCurrency does not exist, so what is the
right function?

Bartek
Jérôme Perrin
2006-01-03 08:55:00 UTC
Permalink
Post by Bartłomiej Górny
Hi
In the "Organisation" module there is an Organisation class which has
{'id' : 'social_capital_currency_id',
'type' : 'string',
'portal_type' : 'Currency',
'acquisition_base_category' : ('price_currency'),
'acquisition_portal_type' : ('Currency'),
'acquisition_copy_value' : 0,
'acquisition_mask_value' : 1,
'acquisition_sync_value' :0,
'acquisition_accessor_id' : 'getId',
'mode' : 'w' }
(and the same for _title).
After editing the object (with the stock form), Base_viewDict shows that
social_capital_currency='currency_module/PLN'
You are unlucky, the form was buggy and has been fixed a few days ago. In that
case, the social capital currency is set through the 'price_currency'
category (in the same property sheet). The purpose of this accessor is to
give an alias to getPriceCurrencyId. It calls the method 'getId' on the
object related by the price_currency category (and with portal type
Currency).
If you want to see other examples of this technique, look at the Arrow
property sheet, it defines accessors like getDestinationTitle, which gives
access to the 'title' property on the object linked by the '<destination'
relation.
Post by Bartłomiej Górny
The question is, how to get it by an appropriate getter?
getSocialCapitalCurrencyId and getSocialCapitalCurrencyTitle exist but
return nothing, getSocialCapitalCurrency does not exist, so what is the
right function?
If you use setPriceCurrency('currency_module/PLN') or update your erp5_core
business template, it will work as expected
--
J?rome
Bartłomiej Górny
2006-01-03 18:44:49 UTC
Permalink
Now, a getter created in this way (like getSocialCapitalCurrencyId)
checks portal type and return none if the type of related object is not
correct. Can a property sheet create setters which would perform a
similar check?
the portal type here is not meant to be checked, CMFCategory creates relations
as a colored graph, portal type is the color. The idea is that you can have
an Organisation as source_section and a Person as source_section, you call
getSourceSection(portal_type='Organisation')
setSourceSection(p, portal_type='Person')
So I can have multiple objects of different types under one category...
ok, got it. And to have multiple objects in one category I have to pass
portal_type as a keyword argument to the setter, correct?

A few more emails, and we will have a man page ready :)

Bartek
Jérôme Perrin
2006-01-06 18:56:15 UTC
Permalink
Post by Bartłomiej Górny
Now, a getter created in this way (like getSocialCapitalCurrencyId)
checks portal type and return none if the type of related object is not
correct. Can a property sheet create setters which would perform a
similar check?
the portal type here is not meant to be checked, CMFCategory creates
relations as a colored graph, portal type is the color. The idea is that
you can have an Organisation as source_section and a Person as
getSourceSection(portal_type='Organisation')
setSourceSection(p, portal_type='Person')
So I can have multiple objects of different types under one category...
ok, got it. And to have multiple objects in one category I have to pass
portal_type as a keyword argument to the setter, correct?
Strictly saying, if you want to have multiple objects in one category, you can
just call the list setter (eg. setSourceSectionList). Specifying the portal
type is to have different colors on the same relation, it's like if the
relation is not only based on the category but rather on the category and the
portal type.
You can have a look at test_14_multiplePortalTypes in
Products/CMFCategory/tests/testCMFCategory.py to see how it works.
--
J?rome
Loading...