diff --git a/attributs.py b/attributs.py index 5113767..492b9bd 100644 --- a/attributs.py +++ b/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