Discussion:
[Modeling-users] Handling custom types for attributes
Mario Ruggier
2003-12-21 15:59:00 UTC
Permalink
Hello!

I would like to use custom FixedPoint values for an attribute of an
object.
So, I do as the example in Chapter 9 of the userguide suggests... so I
define
the "private" methods obj._setX(val) and obj._getX(). However, when the
client code calls the corresponding public setX and getX methods, the
private ones are never called! Any ideas what I may be missing out on?
I am using 0.9-pre-16 of modeling plus bug862182.patch
(no other patches I think).

Another small point: the example _get method in:
<http://modeling.sourceforge.net/UserGuide/attribute-custom-type-
example.html>
should surely read:

if not self._price:
return None

as opposed to (if self._price: ... )

Cheers, mario
Sebastien Bigaret
2003-12-21 17:08:01 UTC
Permalink
Hi,
Post by Mario Ruggier
Hello!
I would like to use custom FixedPoint values for an attribute of an object.
So, I do as the example in Chapter 9 of the userguide suggests... so I define
the "private" methods obj._setX(val) and obj._getX(). However, when the
client code calls the corresponding public setX and getX methods, the
private ones are never called! Any ideas what I may be missing out on?
I am using 0.9-pre-16 of modeling plus bug862182.patch
(no other patches I think).
Well, I think there should be something obscure in the doc. if it made
you think that public methods call the corresponding private ones. It is
definitely not the case (at least by default, nothing prevents you from
doing this).

Private accessors (as searched by KeyValueCoding.storedValueForKey)
are the only one used by the framework. That's why they can be used,
in particular, to define transformation from sql types to custom
types.

Without more info. I cannot really tell why this bothers you so much :)
Post by Mario Ruggier
<http://modeling.sourceforge.net/UserGuide/attribute-custom-type-
example.html>
return None
as opposed to (if self._price: ... )
Absolutely, thanks!

-- Sébastien.
Mario Ruggier
2003-12-21 17:28:01 UTC
Permalink
Post by Sebastien Bigaret
Post by Mario Ruggier
I would like to use custom FixedPoint values for an attribute of an
object.
So, I do as the example in Chapter 9 of the userguide suggests... so
I define
the "private" methods obj._setX(val) and obj._getX(). However, when
the
client code calls the corresponding public setX and getX methods, the
private ones are never called! Any ideas what I may be missing out on?
I am using 0.9-pre-16 of modeling plus bug862182.patch
(no other patches I think).
Well, I think there should be something obscure in the doc. if it made
you think that public methods call the corresponding private ones. It
is
definitely not the case (at least by default, nothing prevents you from
doing this).
Private accessors (as searched by KeyValueCoding.storedValueForKey)
are the only one used by the framework. That's why they can be used,
in particular, to define transformation from sql types to custom
types.
Without more info. I cannot really tell why this bothers you so much :)
Hmmn, I have mis-assumed ;((

It bothers me because it does not do what I expect!
If I add the following "balance" methods to a MyCustomObject class:

def _setBalance(self, value):
if value is None:
self._balance=None
else:
self._balance = FixedPoint(value, 6)

def _getBalance(self):
if not self._balance:
return None
else:
return str(self._balance)
Post by Sebastien Bigaret
Post by Mario Ruggier
a = MyCustomObject()
a.getBalance()
''
Post by Sebastien Bigaret
Post by Mario Ruggier
a.setBalance(FixedPoint('123.456'))
a.getBalance()
FixedPoint('123.46', 2)
Thus, on first getBalance() I should get None.
And on second getBalance() I should get a FixedPoint of pecision 6 not
2.

I am missing something! It is late weekend, and I stop!

Cheers, mario

Loading...