Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
E
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ayush Tiwari
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
...
@@ -42,6 +42,27 @@ from Products.PythonScripts.standard import url_quote_plus
from
Products.Formulator.Errors
import
FormValidationError
,
ValidationError
from
Products.Formulator.Errors
import
FormValidationError
,
ValidationError
import
string
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
):
class
FormBoxWidget
(
Widget
.
Widget
):
"""
"""
...
@@ -103,20 +124,8 @@ class FormBoxWidget(Widget.Widget):
...
@@ -103,20 +124,8 @@ class FormBoxWidget(Widget.Widget):
"""
"""
target_id
=
field
.
get_value
(
'formbox_target_id'
)
target_id
=
field
.
get_value
(
'formbox_target_id'
)
if
target_id
:
if
target_id
:
other
=
REQUEST
.
other
with
getFormBoxContext
(
field
,
REQUEST
)
as
context
:
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
)
return
getattr
(
context
,
target_id
)(
REQUEST
=
REQUEST
,
key_prefix
=
key
)
return
getattr
(
context
,
target_id
)(
REQUEST
=
REQUEST
,
key_prefix
=
key
)
finally
:
other
[
'here'
]
=
here
if
cell
:
other
[
'cell'
]
=
cell
return
''
return
''
class
FormBoxEditor
:
class
FormBoxEditor
:
...
@@ -175,29 +184,26 @@ class FormBoxValidator(Validator.Validator):
...
@@ -175,29 +184,26 @@ class FormBoxValidator(Validator.Validator):
required_not_found
=
'Input is required but no input given.'
required_not_found
=
'Input is required but no input given.'
def
validate
(
self
,
field
,
key
,
REQUEST
):
def
validate
(
self
,
field
,
key
,
REQUEST
):
# XXX hardcoded acquisition
# TODO: Handle 'cell' for validation inside listboxes,
# TODO: Handle 'cell' for validation inside listboxes,
# like it is done for rendering.
# like it is done for rendering.
here
=
field
.
aq_parent
.
aq_parent
context_method_id
=
field
.
get_value
(
'context_method_id'
)
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'
)
formbox_target_id
=
field
.
get_value
(
'formbox_target_id'
)
# Get current error fields
# Get current error fields
current_field_errors
=
REQUEST
.
get
(
'field_errors'
,
[])
current_field_errors
=
REQUEST
.
get
(
'field_errors'
,
[])
# XXX Hardcode script name
with
getFormBoxContext
(
field
,
REQUEST
)
as
here
:
result
,
result_type
=
here
.
Base_edit
(
formbox_target_id
,
silent_mode
=
1
,
key_prefix
=
key
)
# XXX Hardcode script name
if
result_type
==
'edit'
:
result
,
result_type
=
here
.
Base_edit
(
formbox_target_id
,
silent_mode
=
1
,
key_prefix
=
key
)
return
FormBoxEditor
(
result
,
context_method_id
)
if
result_type
==
'edit'
:
elif
result_type
==
'form'
:
return
FormBoxEditor
(
result
,
context_method_id
)
formbox_field_errors
=
REQUEST
.
get
(
'field_errors'
,
[])
elif
result_type
==
'form'
:
current_field_errors
.
extend
(
formbox_field_errors
)
formbox_field_errors
=
REQUEST
.
get
(
'field_errors'
,
[])
REQUEST
.
set
(
'field_errors'
,
current_field_errors
)
current_field_errors
.
extend
(
formbox_field_errors
)
getattr
(
here
,
formbox_target_id
).
validate_all_to_request
(
REQUEST
,
key_prefix
=
key
)
REQUEST
.
set
(
'field_errors'
,
current_field_errors
)
else
:
getattr
(
here
,
formbox_target_id
).
validate_all_to_request
(
REQUEST
,
key_prefix
=
key
)
raise
NotImplementedError
,
result_type
else
:
raise
NotImplementedError
,
result_type
FormBoxWidgetInstance
=
FormBoxWidget
()
FormBoxWidgetInstance
=
FormBoxWidget
()
FormBoxValidatorInstance
=
FormBoxValidator
()
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