Commit 5b13e691 authored by Yusei Tahara's avatar Yusei Tahara

If original template field of a proxy field has its own get_value

implementation, then stop caching and call registered special function
which should behave as the special get_value method. This change fixes
a bug tested on TestProxyField.test_proxifyParallelListField.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@35458 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 0207a057
......@@ -232,14 +232,7 @@ class ParallelListField(ZMIField):
Optionally pass keyword arguments that get passed to TALES
expression.
"""
result = MARKER
key = KEYWORD % id
if (REQUEST is not None) and \
(REQUEST.has_key(key)):
result = REQUEST.get(key)
if result is MARKER:
result = ZMIField.get_value(self, id, REQUEST=REQUEST, **kw)
return result
return paralellListFieldGetValue(self, id, REQUEST=REQUEST, **kw)
def generateSubForm(self, value, REQUEST):
item_list = [x for x in self.get_value('items', REQUEST=REQUEST)
......@@ -274,8 +267,20 @@ def generateSubForm(self, value, REQUEST):
empty_sub_field_property_dict['value'] = value_list
return [empty_sub_field_property_dict]
def paralellListFieldGetValue(field, id, REQUEST=None, **kw):
result = MARKER
key = KEYWORD % id
if REQUEST is not None and REQUEST.has_key(key):
result = REQUEST.get(key)
if result is MARKER:
result = ZMIField.get_value(field, id, REQUEST=REQUEST, **kw)
return result
# Register get_value
from Products.ERP5Form.ProxyField import registerOriginalGetValueClassAndArgument
registerOriginalGetValueClassAndArgument(ParallelListField,
('title', 'required', 'size', 'default', 'first_item', 'items'))
registerOriginalGetValueClassAndArgument(
ParallelListField,
('title', 'required', 'size', 'default', 'first_item', 'items'),
paralellListFieldGetValue)
......@@ -648,6 +648,13 @@ class ProxyField(ZMIField):
"""
Return a callable expression and cacheable boolean flag
"""
# Some field types have their own get_value implementation,
# then we must use it always. This check must be done at first.
template_field = self.getRecursiveTemplateField()
# Old ListBox instance might have default attribute. so we need to check it.
if checkOriginalGetValue(template_field, id):
return _USE_ORIGINAL_GET_VALUE_MARKER, True
try:
tales_expr = self.get_tales_expression(id)
except ValueError:
......@@ -667,10 +674,6 @@ class ProxyField(ZMIField):
# Get a normal value.
try:
template_field = self.getRecursiveTemplateField()
# Old ListBox instance might have default attribute. so we need to check it.
if checkOriginalGetValue(template_field, id):
return _USE_ORIGINAL_GET_VALUE_MARKER, True
value = self.get_recursive_orig_value(id)
except KeyError:
# For ListBox and other exceptional fields.
......@@ -698,9 +701,15 @@ class ProxyField(ZMIField):
security.declareProtected('Access contents information', 'get_value')
def get_value(self, id, **kw):
if ((id in self.widget.property_names) or
(not self.is_delegated(id))):
if id in self.widget.property_names:
return ZMIField.get_value(self, id, **kw)
if not self.is_delegated(id):
original_template_field = self.getRecursiveTemplateField()
function = getOriginalGetValueFunction(original_template_field, id)
if function is not None:
return function(self, id, **kw)
else:
return ZMIField.get_value(self, id, **kw)
field = self
proxy_field = self.getTemplateField()
......@@ -770,7 +779,7 @@ class ProxyField(ZMIField):
#
_get_value_exception_dict = {}
def registerOriginalGetValueClassAndArgument(class_, argument_name_list=()):
def registerOriginalGetValueClassAndArgument(class_, argument_name_list=(), get_value_function=None):
"""
if field class has its own get_value implementation and
must use it rather than ProxyField's one, then register it.
......@@ -780,14 +789,18 @@ def registerOriginalGetValueClassAndArgument(class_, argument_name_list=()):
"""
if not isinstance(argument_name_list, (list, tuple)):
argument_name_list = (argument_name_list,)
_get_value_exception_dict[class_] = argument_name_list
if get_value_function is None:
get_value_function = ZMIField.get_value
_get_value_exception_dict[class_] = {'argument_name_list':argument_name_list,
'get_value_function':get_value_function}
def checkOriginalGetValue(instance, argument_name):
"""
if exception data is registered, then return True
"""
class_ = aq_base(instance).__class__
argument_name_list = _get_value_exception_dict.get(class_)
dict_ = _get_value_exception_dict.get(class_, {})
argument_name_list = dict_.get('argument_name_list')
if argument_name_list is None:
return False
......@@ -798,3 +811,8 @@ def checkOriginalGetValue(instance, argument_name):
if argument_name in argument_name_list:
return True
return False
def getOriginalGetValueFunction(instance, argument_name):
class_ = aq_base(instance).__class__
dict_ = _get_value_exception_dict.get(class_, {})
return dict_.get('get_value_function')
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