From aa4c3584f6ffdaa011e0a135fc7059c3be44050e Mon Sep 17 00:00:00 2001
From: Romain Courteaud <romain@nexedi.com>
Date: Mon, 18 Jun 2007 17:55:11 +0000
Subject: [PATCH] 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
---
 product/ERP5Form/Form.py       | 10 ++++++++--
 product/ERP5Form/ProxyField.py |  5 ++++-
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/product/ERP5Form/Form.py b/product/ERP5Form/Form.py
index e550410cdc..9c5294228d 100644
--- a/product/ERP5Form/Form.py
+++ b/product/ERP5Form/Form.py
@@ -116,11 +116,17 @@ def get_value(self, id, **kw):
 
             # For the 'default' value, we try to get a property value
             # 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:
                 form = self.aq_parent
                 ob = getattr(form, 'aq_parent', None)
-                key = self.id[3:]
+                key = field_id[3:]
                 if value not in (None, ''):
                   # If a default value is defined on the field, it has precedence
                   value = ob.getProperty(key, d=value)
diff --git a/product/ERP5Form/ProxyField.py b/product/ERP5Form/ProxyField.py
index 92d5b5385f..fa204fdb0b 100644
--- a/product/ERP5Form/ProxyField.py
+++ b/product/ERP5Form/ProxyField.py
@@ -123,7 +123,7 @@ class ProxyValidator(Validator.Validator):
   property_names = []
 
   def validate(self, field, key, REQUEST):
-    proxy_field = field.getTemplateField()
+    proxy_field = field.getRecursiveTemplateField()
     try:
       result = proxy_field.validator.validate(field, key, REQUEST)
     except ValidationError, error:
@@ -456,6 +456,9 @@ class ProxyField(ZMIField):
     else:
       proxy_field = self.getTemplateField()
       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)
     return result
 
-- 
2.30.9