Commit 3126be1b authored by Jérome Perrin's avatar Jérome Perrin

'format' in render_dict does not have to be based on input_style, as it's only...

'format' in render_dict does not have to be based on input_style, as it's only used to represent precision.



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@28662 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 306c0e45
......@@ -140,6 +140,14 @@ class TestFloatField(unittest.TestCase):
self.field.values['precision'] = 2
self.field.values['editable'] = 0
self.assertEquals('1 000.00', self.field.render(1000))
def test_render_dict(self):
self.field.values['input_style'] = '-1 234.5'
self.field.values['precision'] = 4
self.assertEquals(dict(query=0.12345,
format='0.0000',
type='float'),
self.field.render_dict(0.12345))
def test_render_string_value(self):
self.field.values['precision'] = 2
......
......@@ -1417,17 +1417,19 @@ class FloatWidget(TextWidget):
format of provided value.
query : Passthrough of given value.
"""
input_style = field.get_value('input_style')
precision = field.get_value('precision')
if precision not in (None, '') and precision != 0:
for x in xrange(1, precision):
input_style += '5'
else:
input_style = input_style.split('.')[0]
format = '0'
if precision:
format = '0.'
# in 'format', the only important thing is the number of decimal places,
# so we add some places until we reach the precision defined on the
# field.
for x in xrange(0, precision):
format += '0'
if isinstance(value, unicode):
value = value.encode(field.get_form_encoding())
return {'query': value,
'format': input_style,
'format': format,
'type': 'float'}
FloatWidgetInstance = FloatWidget()
......
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