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
Labels
Merge Requests
137
Merge Requests
137
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
Jobs
Commits
Open sidebar
nexedi
erp5
Commits
8d41aaf0
Commit
8d41aaf0
authored
Jan 19, 2016
by
Kazuhiko Shiozaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Formulator: support required property in BooleanValidator that is used in CheckBoxField.
parent
18dd0a2c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
1 deletion
+25
-1
product/Formulator/Validator.py
product/Formulator/Validator.py
+16
-1
product/Formulator/tests/testFormValidator.py
product/Formulator/tests/testFormValidator.py
+9
-0
No files found.
product/Formulator/Validator.py
View file @
8d41aaf0
...
@@ -227,13 +227,28 @@ class PatternValidator(StringValidator):
...
@@ -227,13 +227,28 @@ class PatternValidator(StringValidator):
PatternValidatorInstance
=
PatternValidator
()
PatternValidatorInstance
=
PatternValidator
()
class
BooleanValidator
(
Validator
):
class
BooleanValidator
(
Validator
):
property_names
=
Validator
.
property_names
+
[
'required'
]
required
=
fields
.
CheckBoxField
(
'required'
,
title
=
'Required'
,
description
=
(
"Checked if the field is required; the user has to check."
),
default
=
0
)
message_names
=
Validator
.
message_names
+
[
'required_not_found'
]
required_not_found
=
'This field is mandatory.'
def
validate
(
self
,
field
,
key
,
REQUEST
):
def
validate
(
self
,
field
,
key
,
REQUEST
):
result
=
REQUEST
.
get
(
key
,
REQUEST
.
get
(
'default_%s'
%
key
))
result
=
REQUEST
.
get
(
key
,
REQUEST
.
get
(
'default_%s'
%
key
))
if
result
is
None
:
if
result
is
None
:
raise
KeyError
(
'Field %r is not present in request object.'
%
field
.
id
)
raise
KeyError
(
'Field %r is not present in request object.'
%
field
.
id
)
# XXX If the checkbox is hidden, Widget_render_hidden is used instead of
# XXX If the checkbox is hidden, Widget_render_hidden is used instead of
# CheckBoxWidget_render, and ':int' suffix is missing.
# CheckBoxWidget_render, and ':int' suffix is missing.
return
result
and
result
!=
'0'
and
1
or
0
value
=
result
and
result
!=
'0'
and
1
or
0
if
not
value
and
field
.
get_value
(
'required'
):
self
.
raise_error
(
'required_not_found'
,
field
)
return
value
BooleanValidatorInstance
=
BooleanValidator
()
BooleanValidatorInstance
=
BooleanValidator
()
...
...
product/Formulator/tests/testFormValidator.py
View file @
8d41aaf0
...
@@ -179,6 +179,15 @@ class BooleanValidatorTestCase(ValidatorTestCase):
...
@@ -179,6 +179,15 @@ class BooleanValidatorTestCase(ValidatorTestCase):
TestField
(
'f'
),
TestField
(
'f'
),
'f'
,
{
'f'
:
0
})
'f'
,
{
'f'
:
0
})
self
.
assertEqual
(
0
,
result
)
self
.
assertEqual
(
0
,
result
)
result
=
self
.
v
.
validate
(
TestField
(
'f'
,
required
=
1
),
'f'
,
{
'f'
:
1
})
self
.
assertEqual
(
1
,
result
)
self
.
assertValidatorRaises
(
Validator
.
ValidationError
,
'required_not_found'
,
self
.
v
.
validate
,
TestField
(
'f'
,
required
=
1
),
'f'
,
{
'f'
:
0
})
class
IntegerValidatorTestCase
(
ValidatorTestCase
):
class
IntegerValidatorTestCase
(
ValidatorTestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
...
...
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