[attributs] methodes __add__ et __sub__ sur les floatAttr et intAttr
This commit is contained in:
parent
24721ddc98
commit
3a3d51e408
1 changed files with 35 additions and 1 deletions
36
attributs.py
36
attributs.py
|
@ -410,6 +410,18 @@ class intAttr(Attr):
|
|||
|
||||
python_type = int
|
||||
|
||||
def __add__(self, obj):
|
||||
if isinstance(obj, self.__class__):
|
||||
return self.value.__add__(obj.value)
|
||||
else:
|
||||
return self.value.__add__(obj)
|
||||
|
||||
def __sub__(self, obj):
|
||||
if isinstance(obj, self.__class__):
|
||||
return self.value.__sub__(obj.value)
|
||||
else:
|
||||
return self.value.__sub__(obj)
|
||||
|
||||
def parse_value(self, val):
|
||||
if self.python_type(val) < 0:
|
||||
raise ValueError("Valeur entière invalide : %r" % val)
|
||||
|
@ -418,6 +430,28 @@ class intAttr(Attr):
|
|||
def __unicode__(self):
|
||||
return unicode(self.value)
|
||||
|
||||
class floatAttr(Attr):
|
||||
|
||||
python_type = float
|
||||
|
||||
def __add__(self, obj):
|
||||
if isinstance(obj, self.__class__):
|
||||
return self.value.__add__(obj.value)
|
||||
else:
|
||||
return self.value.__add__(obj)
|
||||
|
||||
def __sub__(self, obj):
|
||||
if isinstance(obj, self.__class__):
|
||||
return self.value.__sub__(obj.value)
|
||||
else:
|
||||
return self.value.__sub__(obj)
|
||||
|
||||
def parse_value(self, val):
|
||||
self.value = self.python_type(val)
|
||||
|
||||
def __unicode__(self):
|
||||
return unicode(self.value)
|
||||
|
||||
class boolAttr(Attr):
|
||||
|
||||
python_type = bool
|
||||
|
@ -815,7 +849,7 @@ class droits(Attr):
|
|||
return self.value in modifiables and super(droits, self).is_modifiable(liste_droits)
|
||||
|
||||
@crans_attribute
|
||||
class solde(Attr):
|
||||
class solde(floatAttr):
|
||||
python_type = float
|
||||
singlevalue = True
|
||||
concurent = False
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue