Commit 6e330fa7 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

add context_method_id in FormBox so that we can switch context before rendering the target form.

parent 99963bac
...@@ -65,6 +65,7 @@ class FormBoxWidget(Widget.Widget): ...@@ -65,6 +65,7 @@ class FormBoxWidget(Widget.Widget):
property_names = Widget.Widget.property_names + [ property_names = Widget.Widget.property_names + [
'formbox_target_id', \ 'formbox_target_id', \
'context_method_id', \
] ]
# This name was changed to prevent naming collision with ProxyField # This name was changed to prevent naming collision with ProxyField
...@@ -76,6 +77,14 @@ class FormBoxWidget(Widget.Widget): ...@@ -76,6 +77,14 @@ class FormBoxWidget(Widget.Widget):
default="", default="",
required=0) required=0)
context_method_id = fields.StringField(
'context_method_id',
title='Context method ID',
description=(
"ID of the method that returns a context for this box."),
default="",
required=0)
default = fields.StringField( default = fields.StringField(
'default', 'default',
title='Default', title='Default',
...@@ -101,6 +110,10 @@ class FormBoxWidget(Widget.Widget): ...@@ -101,6 +110,10 @@ class FormBoxWidget(Widget.Widget):
target_id = field.get_value('formbox_target_id') target_id = field.get_value('formbox_target_id')
if target_id not in (None, ''): if target_id not in (None, ''):
here = REQUEST['here'] here = REQUEST['here']
context_method_id = field.get_value('context_method_id')
if context_method_id:
original_here = here
REQUEST['here'] = here = getattr(here, context_method_id)()
# If 'cell' is not defined, we define 'cell' just same as 'here', so # If 'cell' is not defined, we define 'cell' just same as 'here', so
# that we can use the same formbox for both ListBox and non-ListBox # that we can use the same formbox for both ListBox and non-ListBox
# using 'cell' parameter. # using 'cell' parameter.
...@@ -114,6 +127,9 @@ class FormBoxWidget(Widget.Widget): ...@@ -114,6 +127,9 @@ class FormBoxWidget(Widget.Widget):
(field.id, field.aq_parent.id)) (field.id, field.aq_parent.id))
else: else:
result = form(REQUEST=REQUEST, key_prefix=key) result = form(REQUEST=REQUEST, key_prefix=key)
finally:
if context_method_id:
REQUEST['here'] = original_here
return result return result
class FormBoxEditor: class FormBoxEditor:
...@@ -165,6 +181,9 @@ class FormBoxValidator(Validator.Validator): ...@@ -165,6 +181,9 @@ class FormBoxValidator(Validator.Validator):
def validate(self, field, key, REQUEST): def validate(self, field, key, REQUEST):
# XXX hardcoded acquisition # XXX hardcoded acquisition
here = field.aq_parent.aq_parent 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)()
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
......
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