From 0fb1493b53466acee83bdfb422236168a1aa3936 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com>
Date: Fri, 17 Aug 2007 14:00:17 +0000
Subject: [PATCH] ListBox.get_value(render_format='list') was not working
 properly with proxyfield, because the renderer class was using the target
 listbox field. Handle the case of proxy field specificly so that the original
 proxyfield is used by the renderer, and calls to get_value are looked up
 properly.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@15729 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5Form/ListBox.py           | 11 ++++++--
 product/ERP5Form/tests/testListBox.py | 39 +++++++++++++++++++++++++++
 2 files changed, 48 insertions(+), 2 deletions(-)

diff --git a/product/ERP5Form/ListBox.py b/product/ERP5Form/ListBox.py
index b2de23078f..0711f2cafe 100644
--- a/product/ERP5Form/ListBox.py
+++ b/product/ERP5Form/ListBox.py
@@ -3013,8 +3013,15 @@ class ListBox(ZMIField):
   def get_value(self, id, **kw):
     if (id == 'default'):
       if (kw.get('render_format') in ('list', )):
-        return self.widget.render(self, self.generate_field_key(), None,
-                                  kw.get('REQUEST'),
+        request = kw.get('REQUEST', None)
+        if request is None:
+          request = get_request()
+        # here the field can be a a proxyfield target, in this case just find
+        # back the original proxy field so that renderer's calls to .get_value
+        # are called on the proxyfield.
+        field = request.get('field__proxyfield_%s_%s' % (self.id, id), self)
+        return self.widget.render(field, self.generate_field_key(), None,
+                                  request,
                                   render_format=kw.get('render_format'))
       else:
         return None
diff --git a/product/ERP5Form/tests/testListBox.py b/product/ERP5Form/tests/testListBox.py
index b04f49942e..2e3f90bcc3 100644
--- a/product/ERP5Form/tests/testListBox.py
+++ b/product/ERP5Form/tests/testListBox.py
@@ -40,6 +40,7 @@ from Products.ERP5Type.tests.utils import createZODBPythonScript
 from ZPublisher.HTTPRequest import FileUpload
 from StringIO import StringIO
 from Products.ERP5Form.Selection import Selection
+from Products.ERP5Form.Form import ERP5Form
 
 
 class DummyFieldStorage:
@@ -331,6 +332,44 @@ return []
     html = listbox.render(REQUEST=request)
     self.failUnless('Object Title' in html, html)
 
+  def test_ProxyFieldRenderFormatLines(self):
+    # tests that listbox default value in render_format=list mode is
+    # compatible with proxy field.
+    portal = self.getPortal()
+    portal.ListBoxZuite_reset()
+    form = portal.FooModule_viewFooList
+    listbox = form.listbox
+    listbox.ListBox_setPropertyList(
+      field_list_method='contentValues',
+      field_columns=['listbox_value | Title',],)
+    
+    # create a form, to store our proxy field inside
+    portal._setObject('Test_view',
+                      ERP5Form('Test_view', 'View'))
+    portal.Test_view.manage_addField('listbox', 'listbox', 'ProxyField')
+    proxy_field = portal.Test_view.listbox
+    proxy_field.manage_edit_xmlrpc(dict(
+            form_id=form.getId(), field_id='listbox',
+            columns=[('proxy_value', 'Proxy')]))
+
+    # this proxy field will not delegate its "columns" value
+    proxy_field._surcharged_edit(dict(columns=[('proxy_value', 'Proxy')]),
+                                ['columns'])
+    
+    request = get_request()
+    request['here'] = portal.foo_module
+    line_list = proxy_field.get_value('default',
+                      render_format='list', REQUEST=request)
+    self.failUnless(isinstance(line_list, list))
+
+    title_line = line_list[0]
+    self.failUnless(title_line.isTitleLine())
+
+    # title of columns is the value overloaded by the proxy field.
+    self.assertEquals([('proxy_value', 'Proxy')],
+                      title_line.getColumnItemList())
+
+
 if __name__ == '__main__':
   framework()
 else:
-- 
2.30.9