Commit 3a3d51e4 authored by Valentin Samir's avatar Valentin Samir

[attributs] methodes __add__ et __sub__ sur les floatAttr et intAttr

parent 24721ddc
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment