Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Sebastien Robin
erp5
Commits
64c1fd42
Commit
64c1fd42
authored
Jan 25, 2013
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Formulator: clean up FloatWidget.format_value
parent
ccdcbe59
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
43 deletions
+26
-43
product/Formulator/Widget.py
product/Formulator/Widget.py
+26
-43
No files found.
product/Formulator/Widget.py
View file @
64c1fd42
...
@@ -1807,38 +1807,30 @@ class FloatWidget(TextWidget):
...
@@ -1807,38 +1807,30 @@ class FloatWidget(TextWidget):
if
value
not
in
(
None
,
''
):
if
value
not
in
(
None
,
''
):
precision
=
field
.
get_value
(
'precision'
)
precision
=
field
.
get_value
(
'precision'
)
input_style
=
field
.
get_value
(
'input_style'
)
input_style
=
field
.
get_value
(
'input_style'
)
percent
=
0
percent
=
'%'
in
input_style
original_value
=
value
if
input_style
.
find
(
'%'
)
>=
0
:
percent
=
1
try
:
try
:
value
=
float
(
value
)
*
100
except
ValueError
:
return
value
try
:
float_value
=
float
(
value
)
float_value
=
float
(
value
)
if
percent
:
float_value
*=
100
if
precision
not
in
(
None
,
''
):
if
precision
not
in
(
None
,
''
):
# if we have a precision, then use it now
# if we have a precision, then use it now
value
=
(
'%%0.%sf'
%
precision
)
%
float_value
value
=
(
'%%0.%sf'
%
precision
)
%
float_value
else
:
else
:
value
=
str
(
float_value
)
value
=
str
(
float_value
)
except
ValueError
:
# if this number is displayed in scientific notification,
return
value
# just return it as is
# if this number displayed in scientific notification, just return it as
# is
if
'e'
in
value
:
if
'e'
in
value
:
return
value
return
value
value_list
=
value
.
split
(
'.'
)
value
,
fpart
=
value
.
split
(
'.'
)
integer
=
value_list
[
0
]
except
ValueError
:
return
value
decimal_separator
=
''
decimal_separator
=
''
decimal_point
=
'.'
decimal_point
=
'.'
if
input_style
==
"-1234.5"
:
if
input_style
==
"-1234.5"
:
decimal_point
=
'.'
pass
elif
input_style
==
'-1 234.5'
:
elif
input_style
==
'-1 234.5'
:
decimal_separator
=
' '
decimal_separator
=
' '
decimal_point
=
'.'
elif
input_style
==
'-1 234,5'
:
elif
input_style
==
'-1 234,5'
:
decimal_separator
=
' '
decimal_separator
=
' '
decimal_point
=
','
decimal_point
=
','
...
@@ -1847,37 +1839,28 @@ class FloatWidget(TextWidget):
...
@@ -1847,37 +1839,28 @@ class FloatWidget(TextWidget):
decimal_point
=
','
decimal_point
=
','
elif
input_style
==
'-1,234.5'
:
elif
input_style
==
'-1,234.5'
:
decimal_separator
=
','
decimal_separator
=
','
decimal_point
=
'.'
if
input_style
.
find
(
decimal_separator
)
>=
0
:
if
decimal_separator
in
input_style
:
integer
=
value_list
[
0
]
if
value
.
startswith
(
'-'
):
sign
=
''
if
integer
.
startswith
(
'-'
):
sign
=
'-'
sign
=
'-'
integer
=
integer
[
1
:]
i
=
len
(
integer
)
%
3
value
=
integer
[:
i
]
while
i
!=
len
(
integer
):
value
+=
decimal_separator
+
integer
[
i
:
i
+
3
]
i
+=
3
if
value
[
0
]
==
decimal_separator
:
value
=
value
[
1
:]
value
=
value
[
1
:]
value
=
'%s%s'
%
(
sign
,
value
)
else
:
else
:
value
=
value_list
[
0
]
sign
=
''
i
=
len
(
value
)
%
3
or
3
integer
=
value
[:
i
]
while
i
<
len
(
value
):
integer
+=
decimal_separator
+
value
[
i
:
i
+
3
]
i
+=
3
value
=
sign
+
integer
if
precision
!=
0
:
if
precision
!=
0
:
value
+=
decimal_point
value
+=
decimal_point
if
precision
not
in
(
None
,
''
):
if
precision
:
for
i
in
range
(
0
,
precision
):
value
+=
fpart
[:
precision
].
ljust
(
precision
,
'0'
)
if
i
<
len
(
value_list
[
1
]):
value
+=
value_list
[
1
][
i
]
else
:
value
+=
'0'
else
:
else
:
value
+=
value_list
[
1
]
value
+=
fpart
if
percent
:
if
percent
:
value
+=
'%'
value
+=
'%'
return
value
.
strip
()
return
value
return
''
return
''
def
render
(
self
,
field
,
key
,
value
,
REQUEST
,
render_prefix
=
None
):
def
render
(
self
,
field
,
key
,
value
,
REQUEST
,
render_prefix
=
None
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment