Commit aa4c3584 authored by Romain Courteaud's avatar Romain Courteaud

Fix default value of proxy field.

If an accessor is called, it has to be based on the proxy field id, and not on
his template field.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@14864 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 60b64e0d
...@@ -116,11 +116,17 @@ def get_value(self, id, **kw): ...@@ -116,11 +116,17 @@ def get_value(self, id, **kw):
# For the 'default' value, we try to get a property value # For the 'default' value, we try to get a property value
# stored in the context, only if the field is prefixed with my_. # stored in the context, only if the field is prefixed with my_.
if id == 'default' and self.id[:3] == 'my_': REQUEST = get_request()
if REQUEST is not None:
field_id = REQUEST.get('%s_%s_id' % (self.id, id), self.id)
else:
field_id = self.id
if id == 'default' and field_id.startswith('my_'):
try: try:
form = self.aq_parent form = self.aq_parent
ob = getattr(form, 'aq_parent', None) ob = getattr(form, 'aq_parent', None)
key = self.id[3:] key = field_id[3:]
if value not in (None, ''): if value not in (None, ''):
# If a default value is defined on the field, it has precedence # If a default value is defined on the field, it has precedence
value = ob.getProperty(key, d=value) value = ob.getProperty(key, d=value)
......
...@@ -123,7 +123,7 @@ class ProxyValidator(Validator.Validator): ...@@ -123,7 +123,7 @@ class ProxyValidator(Validator.Validator):
property_names = [] property_names = []
def validate(self, field, key, REQUEST): def validate(self, field, key, REQUEST):
proxy_field = field.getTemplateField() proxy_field = field.getRecursiveTemplateField()
try: try:
result = proxy_field.validator.validate(field, key, REQUEST) result = proxy_field.validator.validate(field, key, REQUEST)
except ValidationError, error: except ValidationError, error:
...@@ -456,6 +456,9 @@ class ProxyField(ZMIField): ...@@ -456,6 +456,9 @@ class ProxyField(ZMIField):
else: else:
proxy_field = self.getTemplateField() proxy_field = self.getTemplateField()
if proxy_field is not None: if proxy_field is not None:
REQUEST = get_request()
REQUEST.set('%s_%s_id' % (proxy_field.id, id),
REQUEST.get('%s_%s_id' % (self.id, id), self.id))
result = proxy_field.get_value(id, **kw) result = proxy_field.get_value(id, **kw)
return result return result
......
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