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
alecs_myu
erp5
Commits
a40266af
Commit
a40266af
authored
Oct 19, 2017
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
FormBox: fix validate() globals to be consistent with render()
parent
e5e57621
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
28 deletions
+34
-28
product/ERP5Form/FormBox.py
product/ERP5Form/FormBox.py
+34
-28
No files found.
product/ERP5Form/FormBox.py
View file @
a40266af
...
...
@@ -42,6 +42,27 @@ from Products.PythonScripts.standard import url_quote_plus
from
Products.Formulator.Errors
import
FormValidationError
,
ValidationError
import
string
from
contextlib
import
contextmanager
@
contextmanager
def
getFormBoxContext
(
field
,
REQUEST
):
other
=
REQUEST
.
other
has_here
=
'here'
in
other
# XXX hardcoded acquisition
here
=
other
[
'here'
]
if
has_here
else
field
.
aq_parent
.
aq_parent
context_method_id
=
field
.
get_value
(
'context_method_id'
)
try
:
cell
=
other
.
pop
(
'cell'
,
None
)
context
=
cell
or
here
if
context_method_id
:
context
=
getattr
(
context
,
context_method_id
)(
field
=
field
,
REQUEST
=
REQUEST
)
yield
context
finally
:
if
has_here
:
other
[
'here'
]
=
here
if
cell
:
other
[
'cell'
]
=
cell
class
FormBoxWidget
(
Widget
.
Widget
):
"""
...
...
@@ -103,20 +124,8 @@ class FormBoxWidget(Widget.Widget):
"""
target_id
=
field
.
get_value
(
'formbox_target_id'
)
if
target_id
:
other
=
REQUEST
.
other
here
=
other
[
'here'
]
context_method_id
=
field
.
get_value
(
'context_method_id'
)
try
:
cell
=
other
.
pop
(
'cell'
,
None
)
context
=
cell
or
here
if
context_method_id
:
context
=
getattr
(
context
,
context_method_id
)(
field
=
field
,
REQUEST
=
REQUEST
)
with
getFormBoxContext
(
field
,
REQUEST
)
as
context
:
return
getattr
(
context
,
target_id
)(
REQUEST
=
REQUEST
,
key_prefix
=
key
)
finally
:
other
[
'here'
]
=
here
if
cell
:
other
[
'cell'
]
=
cell
return
''
class
FormBoxEditor
:
...
...
@@ -175,29 +184,26 @@ class FormBoxValidator(Validator.Validator):
required_not_found
=
'Input is required but no input given.'
def
validate
(
self
,
field
,
key
,
REQUEST
):
# XXX hardcoded acquisition
# TODO: Handle 'cell' for validation inside listboxes,
# like it is done for rendering.
here
=
field
.
aq_parent
.
aq_parent
context_method_id
=
field
.
get_value
(
'context_method_id'
)
if
context_method_id
:
here
=
getattr
(
here
,
context_method_id
)(
field
=
field
,
REQUEST
=
REQUEST
)
formbox_target_id
=
field
.
get_value
(
'formbox_target_id'
)
# Get current error fields
current_field_errors
=
REQUEST
.
get
(
'field_errors'
,
[])
# XXX Hardcode script name
result
,
result_type
=
here
.
Base_edit
(
formbox_target_id
,
silent_mode
=
1
,
key_prefix
=
key
)
if
result_type
==
'edit'
:
return
FormBoxEditor
(
result
,
context_method_id
)
elif
result_type
==
'form'
:
formbox_field_errors
=
REQUEST
.
get
(
'field_errors'
,
[])
current_field_errors
.
extend
(
formbox_field_errors
)
REQUEST
.
set
(
'field_errors'
,
current_field_errors
)
getattr
(
here
,
formbox_target_id
).
validate_all_to_request
(
REQUEST
,
key_prefix
=
key
)
else
:
raise
NotImplementedError
,
result_type
with
getFormBoxContext
(
field
,
REQUEST
)
as
here
:
# XXX Hardcode script name
result
,
result_type
=
here
.
Base_edit
(
formbox_target_id
,
silent_mode
=
1
,
key_prefix
=
key
)
if
result_type
==
'edit'
:
return
FormBoxEditor
(
result
,
context_method_id
)
elif
result_type
==
'form'
:
formbox_field_errors
=
REQUEST
.
get
(
'field_errors'
,
[])
current_field_errors
.
extend
(
formbox_field_errors
)
REQUEST
.
set
(
'field_errors'
,
current_field_errors
)
getattr
(
here
,
formbox_target_id
).
validate_all_to_request
(
REQUEST
,
key_prefix
=
key
)
else
:
raise
NotImplementedError
,
result_type
FormBoxWidgetInstance
=
FormBoxWidget
()
FormBoxValidatorInstance
=
FormBoxValidator
()
...
...
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