Commit 1875022b authored by Jérome Perrin's avatar Jérome Perrin

The previous commit introduced a problem, float fields were no longer able to

display non float values.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@15258 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 33d91234
......@@ -1059,10 +1059,11 @@ class FloatWidget(TextWidget):
if input_style.find('%')>=0:
percent=1
value = float(value) * 100
if precision:
value = round(value, precision)
try :
value = str(float(value))
float_value = float(value)
if precision:
float_value = round(float_value, precision)
value = str(float_value)
except ValueError:
return value
else:
......
......@@ -60,12 +60,18 @@ class TestFloatField(unittest.TestCase):
self.assertEquals('0.01', self.widget.format_value(self.field, 0.011))
# value is rounded
self.assertEquals('0.01', self.widget.format_value(self.field, 0.009999))
def test_render_view(self):
self.field.values['input_style'] = '-1 234.5'
self.field.values['precision'] = 2
self.field.values['editable'] = 0
self.assertEquals('1 000.00', self.field.render(1000))
def test_render_string_value(self):
self.field.values['precision'] = 2
self.field.values['editable'] = 0
self.assertEquals('12.34', self.field.render("12.34"))
self.assertEquals('not float', self.field.render("not float"))
def test_render_big_numbers(self):
self.field.values['precision'] = 2
......
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