Commit 13b4d766 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

set REQUEST['original_context'] in FormBox if context_method_id is used.

so that we can reach the original context where FormBox is used.
also clean up modified REQUEST after rendering the target form.
parent 70db1e05
......@@ -112,13 +112,16 @@ class FormBoxWidget(Widget.Widget):
here = REQUEST['here']
context_method_id = field.get_value('context_method_id')
if context_method_id:
original_here = here
REQUEST['original_context'] = original_here = here
REQUEST['here'] = here = getattr(here, context_method_id)()
# 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
# using 'cell' parameter.
if not REQUEST.has_key('cell'):
set_cell = True
REQUEST.set('cell', here)
else:
set_sell = False
try:
form = getattr(here, target_id)
except AttributeError:
......@@ -130,6 +133,9 @@ class FormBoxWidget(Widget.Widget):
finally:
if context_method_id:
REQUEST['here'] = original_here
del REQUEST.other['original_context']
if set_cell:
del REQUEST.other['cell']
return result
class FormBoxEditor:
......
  • @kazuhiko Everything done here with cell is wrong from the beginning because as soon as it's set, it's used to get values. Reverting the setting of cell in the finally: clause does not solve anything: even if you fix things for the caller, it may still bug for the callees.

    I wish we could have a tree of FormBoxes, of any depth, with a ListBox in some branches. In a project, we have FormBox(FormBox, ListBox):

    • I don't want the inner FormBox to be rendered with cell=here of the outter one.
    • The ListBox removes cell once it's rendered, causing the outter FormBox to crash. Well, here it would be an issue of ListBox, but ListBox inside ListBox is weird.

    Similarly but easier to fix: REQUEST['original_context'] is overridden, which also prevents FormBox inside FormBox if context_method_id is used in both fields.

    And the only way to modify/restore REQUEST safely is to manipulate REQUEST.other directly for everything.

    /cc @romain @jerome @vpelletier @seb

  • Julien Muchembled @jm

    mentioned in merge request !143 (merged)

    ·

    mentioned in merge request !143 (merged)

    Toggle commit list
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