always call base constructor of CapBaseObject to prevent shared fields

This commit is contained in:
Romain Bignon 2013-03-30 22:35:24 +01:00
commit c5ee2aec2a

View file

@ -33,6 +33,7 @@ class Temperature(CapBaseObject):
unit = StringField('Input unit')
def __init__(self, value, unit = u''):
CapBaseObject.__init__(self, value)
self.value = value
if unit not in [u'C', u'F']:
unit = u''
@ -42,7 +43,7 @@ class Temperature(CapBaseObject):
if not self.unit:
return u'%s' % int(round(self.value))
elif self.unit == 'F':
return u'%sF' % int(round(self.value))
return u'%s°F' % int(round(self.value))
else:
return u'%s°F' % int(round((self.value * 9.0 / 5.0) + 32))
@ -50,7 +51,7 @@ class Temperature(CapBaseObject):
if not self.unit:
return u'%s' % int(round(self.value))
elif self.unit == 'C':
return u'%sC' % int(round(self.value))
return u'%s°C' % int(round(self.value))
else:
return u'%s°C' % int(round((self.value - 32.0) * 5.0 / 9.0))