Commit fddb1053 authored by Tristan Cavelier's avatar Tristan Cavelier

WIP FormBox + QuantitySplitSolver

parent 73a92b4b
...@@ -144,7 +144,7 @@ ...@@ -144,7 +144,7 @@
<dictionary> <dictionary>
<item> <item>
<key> <string>_text</string> </key> <key> <string>_text</string> </key>
<value> <string>python:cell.getConfigurationPropertyDict().get(\'delivery_solver\', None)</string> </value> <value> <string>python:here.getConfigurationPropertyDict().get(\'delivery_solver\', None)</string> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
...@@ -157,7 +157,7 @@ ...@@ -157,7 +157,7 @@
<dictionary> <dictionary>
<item> <item>
<key> <string>_text</string> </key> <key> <string>_text</string> </key>
<value> <string>python:[(here.Base_translateString(x.getSolverActionTitle() or \'\'), x.getId()) for x in cell.searchDeliverySolverList()]</string> </value> <value> <string>python:[(here.Base_translateString(x.getSolverActionTitle() or \'\'), x.getId()) for x in here.searchDeliverySolverList()]</string> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
......
...@@ -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()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment