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
...@@ -141,6 +141,14 @@ class TestFloatField(unittest.TestCase): ...@@ -141,6 +141,14 @@ class TestFloatField(unittest.TestCase):
self.field.values['editable'] = 0 self.field.values['editable'] = 0
self.assertEquals('1 000.00', self.field.render(1000)) 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): def test_render_string_value(self):
self.field.values['precision'] = 2 self.field.values['precision'] = 2
self.field.values['editable'] = 0 self.field.values['editable'] = 0
......
...@@ -1417,17 +1417,19 @@ class FloatWidget(TextWidget): ...@@ -1417,17 +1417,19 @@ class FloatWidget(TextWidget):
format of provided value. format of provided value.
query : Passthrough of given value. query : Passthrough of given value.
""" """
input_style = field.get_value('input_style')
precision = field.get_value('precision') precision = field.get_value('precision')
if precision not in (None, '') and precision != 0: format = '0'
for x in xrange(1, precision): if precision:
input_style += '5' format = '0.'
else: # in 'format', the only important thing is the number of decimal places,
input_style = input_style.split('.')[0] # 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): if isinstance(value, unicode):
value = value.encode(field.get_form_encoding()) value = value.encode(field.get_form_encoding())
return {'query': value, return {'query': value,
'format': input_style, 'format': format,
'type': 'float'} 'type': 'float'}
FloatWidgetInstance = FloatWidget() 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