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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Mikolaï Krol
erp5
Commits
e6631e4b
Commit
e6631e4b
authored
Jun 04, 2014
by
Tatuya Kamada
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Formulator: Add a FloatField validator to take account of the precision and the user input length.
parent
eb5fdbe3
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
66 additions
and
4 deletions
+66
-4
bt5/erp5_ui_test/PathTemplateItem/portal_tests/float_field_zuite/testFloatField.xml
...ateItem/portal_tests/float_field_zuite/testFloatField.xml
+26
-2
bt5/erp5_ui_test/bt/revision
bt5/erp5_ui_test/bt/revision
+1
-1
product/ERP5Form/tests/testFields.py
product/ERP5Form/tests/testFields.py
+19
-0
product/Formulator/Validator.py
product/Formulator/Validator.py
+20
-1
No files found.
bt5/erp5_ui_test/PathTemplateItem/portal_tests/float_field_zuite/testFloatField.xml
View file @
e6631e4b
...
@@ -103,6 +103,31 @@
...
@@ -103,6 +103,31 @@
<td>
//button[@title=\'Save\']
</td>
\n
<td>
//button[@title=\'Save\']
</td>
\n
<td></td>
\n
<td></td>
\n
</tr>
\n
</tr>
\n
<tr>
\n
<td>
verifyText
</td>
\n
<td>
//div[@id="information_area"]
</td>
\n
<td>
Input data has errors. Please look at the error messages below.
</td>
\n
</tr>
\n
<tr>
\n
<td>
verifyText
</td>
\n
<td>
//span[@class="error"]
</td>
\n
<td>
The number you input has too large precision.
</td>
\n
</tr>
\n
<tr>
\n
<td>
type
</td>
\n
<td>
field_my_quantity
</td>
\n
<td>
1000000000000.0
</td>
\n
</tr>
\n
<tr>
\n
<td>
clickAndWait
</td>
\n
<td>
//button[@title=\'Save\']
</td>
\n
<td></td>
\n
</tr>
\n
<tr>
\n
<td>
verifyPortalStatusMessage
</td>
\n
<td>
Data updated.
</td>
\n
<td></td>
\n
</tr>
\n
<tr>
\n
<tr>
\n
<td>
verifyPortalStatusMessage
</td>
\n
<td>
verifyPortalStatusMessage
</td>
\n
<td>
Data updated.
</td>
\n
<td>
Data updated.
</td>
\n
...
@@ -120,8 +145,7 @@
...
@@ -120,8 +145,7 @@
</tr>
\n
</tr>
\n
</tbody></table>
\n
</tbody></table>
\n
</body>
\n
</body>
\n
</html>
\n
</html>
]]>
</unicode>
</value>
]]>
</unicode>
</value>
</item>
</item>
...
...
bt5/erp5_ui_test/bt/revision
View file @
e6631e4b
713
714
\ No newline at end of file
\ No newline at end of file
product/ERP5Form/tests/testFields.py
View file @
e6631e4b
...
@@ -231,6 +231,25 @@ class TestFloatField(ERP5TypeTestCase):
...
@@ -231,6 +231,25 @@ class TestFloatField(ERP5TypeTestCase):
self
.
assertRaises
(
ValidationError
,
self
.
assertRaises
(
ValidationError
,
self
.
validator
.
validate
,
self
.
field
,
'field_test_field'
,
self
.
portal
.
REQUEST
)
self
.
validator
.
validate
,
self
.
field
,
'field_test_field'
,
self
.
portal
.
REQUEST
)
def
test_validate_precision0
(
self
):
# Check the consistency among the precision and user inputs
self
.
field
.
values
[
'input_style'
]
=
'-1,234.5'
self
.
field
.
values
[
'precision'
]
=
0
self
.
portal
.
REQUEST
.
set
(
'field_test_field'
,
'1.00'
)
self
.
assertRaises
(
ValidationError
,
self
.
validator
.
validate
,
self
.
field
,
'field_test_field'
,
self
.
portal
.
REQUEST
)
def
test_validate_precision0_with_percent
(
self
):
# Check the precision and user inputs when the style is '%'
self
.
field
.
values
[
'input_style'
]
=
'-12.5%'
self
.
field
.
values
[
'precision'
]
=
1
self
.
assertEqual
(
'12.5%'
,
self
.
widget
.
format_value
(
self
.
field
,
0.125
))
self
.
portal
.
REQUEST
.
set
(
'field_test_field'
,
'0.1255'
)
self
.
assertRaises
(
ValidationError
,
self
.
validator
.
validate
,
self
.
field
,
'field_test_field'
,
self
.
portal
.
REQUEST
)
def
test_render_odt
(
self
):
def
test_render_odt
(
self
):
self
.
field
.
values
[
'input_style'
]
=
'-1 234.5'
self
.
field
.
values
[
'input_style'
]
=
'-1 234.5'
self
.
field
.
values
[
'default'
]
=
1000
self
.
field
.
values
[
'default'
]
=
1000
...
...
product/Formulator/Validator.py
View file @
e6631e4b
...
@@ -290,9 +290,27 @@ class IntegerValidator(StringBaseValidator):
...
@@ -290,9 +290,27 @@ class IntegerValidator(StringBaseValidator):
IntegerValidatorInstance
=
IntegerValidator
()
IntegerValidatorInstance
=
IntegerValidator
()
class
FloatValidator
(
StringBaseValidator
):
class
FloatValidator
(
StringBaseValidator
):
message_names
=
StringBaseValidator
.
message_names
+
[
'not_float'
]
message_names
=
StringBaseValidator
.
message_names
+
[
'not_float'
,
'too_large_precision'
]
not_float
=
"You did not enter a floating point number."
not_float
=
"You did not enter a floating point number."
too_large_precision
=
"The number you input has too large precision."
def
_validatePrecision
(
self
,
field
,
value
,
decimal_point
,
input_style
):
""" Validate the consistency among the precision and the user inputs """
if
not
field
.
has_value
(
'precision'
):
return
value
precision
=
field
.
get_value
(
'precision'
)
if
precision
==
''
or
precision
is
None
:
# need to validate when the precision is 0
return
value
index
=
value
.
find
(
decimal_point
)
if
index
<
0
:
return
value
input_precision_length
=
len
(
value
[
index
+
1
:])
if
input_precision_length
>
int
(
precision
):
self
.
raise_error
(
'too_large_precision'
,
field
)
return
value
def
validate
(
self
,
field
,
key
,
REQUEST
):
def
validate
(
self
,
field
,
key
,
REQUEST
):
value
=
StringBaseValidator
.
validate
(
self
,
field
,
key
,
REQUEST
)
value
=
StringBaseValidator
.
validate
(
self
,
field
,
key
,
REQUEST
)
...
@@ -326,6 +344,7 @@ class FloatValidator(StringBaseValidator):
...
@@ -326,6 +344,7 @@ class FloatValidator(StringBaseValidator):
value
=
value
.
replace
(
decimal_point
,
'.'
)
value
=
value
.
replace
(
decimal_point
,
'.'
)
if
value
.
find
(
'%'
)
>=
0
:
if
value
.
find
(
'%'
)
>=
0
:
value
=
value
.
replace
(
'%'
,
''
)
value
=
value
.
replace
(
'%'
,
''
)
value
=
self
.
_validatePrecision
(
field
,
value
,
decimal_point
,
input_style
)
try
:
try
:
value
=
float
(
value
)
value
=
float
(
value
)
if
input_style
.
find
(
'%'
)
>=
0
:
if
input_style
.
find
(
'%'
)
>=
0
:
...
...
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