Commit ea89b895 authored by Yoshinori Okuji's avatar Yoshinori Okuji

Support extra_context specified by a proxy field.

This can be used to pass parameters from a proxy field to an underlying field.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@5474 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 331663ea
......@@ -77,6 +77,9 @@ def get_value(self, id, **kw):
except AttributeError :
LOG('ERP5Form', 0,
'portal_preferences not put in TALES context (not installed?)')
extra_context = getattr(self, '_v_extra_context', None)
if extra_context:
kw.update(extra_context)
# This allows to pass some pointer to the local object
# through the REQUEST parameter. Not very clean.
# Used by ListBox to render different items in a list
......
......@@ -55,6 +55,7 @@ class ProxyWidget(Widget.Widget):
property_names = Widget.Widget.property_names + [
'form_id', \
'field_id', \
'extra_context', \
]
form_id = fields.StringField(
......@@ -81,6 +82,13 @@ class ProxyWidget(Widget.Widget):
default="",
required=0)
extra_context = fields.ListTextAreaField(
'extra_context',
title='Extra Context',
description='Additional context variables.',
default=(),
required=0)
def render(self, field, key, value, REQUEST):
"""
......@@ -89,6 +97,11 @@ class ProxyWidget(Widget.Widget):
form = field.aq_parent
proxy_form = getattr(form, field.get_value('form_id'))
proxy_field = getattr(proxy_form, field.get_value('field_id'))
extra_context = field.get_value('extra_context')
if not hasattr(proxy_field, '_v_extra_context'):
proxy_field._v_extra_context = {}
for k, v in extra_context:
proxy_field._v_extra_context[k] = v
return proxy_field.widget.render(proxy_field, key, value, REQUEST)
def render_view(self, field, value):
......@@ -98,6 +111,11 @@ class ProxyWidget(Widget.Widget):
form = field.aq_parent
proxy_form = getattr(form, field.get_value('form_id'))
proxy_field = getattr(proxy_form, field.get_value('field_id'))
extra_context = field.get_value('extra_context')
if not hasattr(proxy_field, '_v_extra_context'):
proxy_field._v_extra_context = {}
for k, v in extra_context:
proxy_field._v_extra_context[k] = v
return proxy_field.widget.render_view(proxy_field, key, value)
class ProxyValidator(Validator.Validator):
......
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