From c028a4369034d7d6cc4954ab416b70ad85dcaae0 Mon Sep 17 00:00:00 2001
From: Nicolas Delaby <nicolas@nexedi.com>
Date: Tue, 18 Nov 2008 12:22:03 +0000
Subject: [PATCH] Propagate render_prefix to be able to display OOoChart in
 ReportSection

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@24621 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5Form/FormulatorPatch.py |  4 ++--
 product/ERP5Form/ListBox.py         |  9 ++++++---
 product/ERP5Form/OOoChart.py        | 16 ++++++++++------
 3 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/product/ERP5Form/FormulatorPatch.py b/product/ERP5Form/FormulatorPatch.py
index 67dd779809c..a0b3f56540e 100644
--- a/product/ERP5Form/FormulatorPatch.py
+++ b/product/ERP5Form/FormulatorPatch.py
@@ -71,7 +71,7 @@ def Field_render(self, value=None, REQUEST=None, key=None, render_prefix=None):
     if value and REQUEST are both None, the 'default' property of
     the field will be used for the value.
     """
-    return self._render_helper(self.generate_field_key(key=key), value, REQUEST)
+    return self._render_helper(self.generate_field_key(key=key), value, REQUEST, render_prefix)
 
 def Field_render_view(self, value=None, REQUEST=None, render_prefix=None):
     """Render value to be viewed.
@@ -84,7 +84,7 @@ def Field_render_sub_field(self, id, value=None, REQUEST=None, key=None, render_
         Added key parameter for ERP5 in order to be compatible with listbox/matrixbox
     """
     return self.sub_form.get_field(id)._render_helper(
-        self.generate_subfield_key(id, key=key), value, REQUEST)
+        self.generate_subfield_key(id, key=key), value, REQUEST, render_prefix)
 
 def Field_generate_subfield_key(self, id, validation=0, key=None):
     """Generate the key Silva uses to render a sub field.
diff --git a/product/ERP5Form/ListBox.py b/product/ERP5Form/ListBox.py
index 9fa201a1aae..4d74df4abc2 100644
--- a/product/ERP5Form/ListBox.py
+++ b/product/ERP5Form/ListBox.py
@@ -395,7 +395,8 @@ class ListBoxWidget(Widget.Widget):
         if REQUEST is None:
           REQUEST = get_request()
         if render_format == 'list':
-          renderer = ListBoxListRenderer(self, field, REQUEST)
+          renderer = ListBoxListRenderer(self, field, REQUEST,
+                                         render_prefix=render_prefix)
         else:
           renderer = ListBoxHTMLRenderer(self, field, REQUEST, render_prefix=render_prefix)
 
@@ -1813,7 +1814,7 @@ class ListBoxRendererLine:
   """This class describes a line in a ListBox to assist ListBoxRenderer.
   """
   def __init__(self, renderer = None, obj = None, index = 0, is_summary = False, context = None,
-               is_open = False, selection_domain = None, depth = 0, domain_title=None):
+               is_open = False, selection_domain = None, depth = 0, domain_title=None, render_prefix=None):
     """In reality, the object is a brain or a brain-like object.
     """
     self.renderer = renderer
@@ -1825,6 +1826,7 @@ class ListBoxRendererLine:
     self.selection_domain = selection_domain
     self.depth = depth
     self.domain_title = domain_title
+    self.render_prefix = render_prefix
 
   def getBrain(self):
     """Return the brain. This can be identical to a real object.
@@ -2625,7 +2627,8 @@ class ListBox(ZMIField):
           self)
         return self.widget.render(field, self.generate_field_key(), None,
                                   request,
-                                  render_format=kw.get('render_format'))
+                                  render_format=kw.get('render_format'),
+                                  render_prefix=kw.get('render_prefix'))
       else:
         return None
     else:
diff --git a/product/ERP5Form/OOoChart.py b/product/ERP5Form/OOoChart.py
index 6534b13c166..8e2c317406a 100644
--- a/product/ERP5Form/OOoChart.py
+++ b/product/ERP5Form/OOoChart.py
@@ -343,7 +343,9 @@ class OOoChartWidget(Widget.Widget):
     listbox_id = field.get_value('listbox_id')
     if listbox_id in ('', None):
       listbox_id = 'listbox'
+    render_prefix = REQUEST.get('render_prefix')
     extra_argument_dict = dict(
+      render_prefix = render_prefix,
       chart_form_id = listbox_form_id,
       chart_field_id = listbox_id,
       chart_title = field.get_value('title'),
@@ -383,7 +385,8 @@ class OOoChartWidget(Widget.Widget):
       Render a Chart in read-only.
     """
     if REQUEST is None: REQUEST=get_request()
-    return self.render(field, key, value, REQUEST, render_format=render_format)
+    return self.render(field, key, value, REQUEST, render_format=render_format,
+                       render_prefix=render_prefix)
 
 
   def render_odf(self, field, key, value, REQUEST, render_format='ooo', render_prefix=None):
@@ -392,7 +395,6 @@ class OOoChartWidget(Widget.Widget):
     """
     form = field.aq_parent
     here = getattr(form, 'aq_parent', REQUEST)
-    extra_context = self.getArgumentDict(field, here.REQUEST)
     content = '''
                   <office:include path="%s/ERP5Site_buildChart" xlink:type="simple" xlink:actuate="onLoad" xlink:show="embed"/>
                   ''' % here.getPath()
@@ -413,7 +415,6 @@ class OOoChartWidget(Widget.Widget):
                          If the format is set to an image type (ex. png)
                          render the chart using that format.
     """
-
     title = field.get_value('title')
     alt = field.get_value('description') or title
     form = field.aq_parent
@@ -431,20 +432,22 @@ class OOoChartWidget(Widget.Widget):
       display = field.get_value('image_display')
       if format in STANDARD_IMAGE_FORMAT_LIST:
         main_content = '''<div class="OOoChartContent">
-          <img class="%s" src="%s?render_format=%s&display=%s" title="%s" alt="%s"/">
+          <img class="%s" src="%s?render_format=%s&display=%s&render_prefix=%s" title="%s" alt="%s"/">
           </div>''' % (css_class,
                        field_absolute_url,
                        format,
                        display,
+                       render_prefix,
                        title,
                        alt)
         return main_content
       elif format == 'raw':
         UrlIconOOo = '%s/misc_/ERP5OOo/OOo.png' % REQUEST['BASEPATH1']
         main_content = '''<div class="OOoChartContent">
-          <a href="%s?render_format=&display=%s"><img src="%s" alt="OOo"/></a></div>
+          <a href="%s?render_format=&display=%s&render_prefix=%s"><img src="%s" alt="OOo"/></a></div>
           ''' % (field_absolute_url,
                  display,
+                 render_prefix,
                  UrlIconOOo)
         return main_content
       elif format == 'pdf':
@@ -453,6 +456,7 @@ class OOoChartWidget(Widget.Widget):
           <a href="%s?render_format=pdf&display=%s"><img src="%s" alt="PDF" /></a>
           </div>''' % (field_absolute_url,
                        display,
+                       render_prefix,
                        UrlIconPdf)
         return main_content
       else:
@@ -466,7 +470,7 @@ class OOoChartWidget(Widget.Widget):
     ooo_template = getattr(here, method_id)
 
     # Render the chart
-    return ooo_template(format=render_format)
+    return ooo_template(format=render_format, **extra_context)
 
 class OOoChartValidator(Validator.Validator):
   """
-- 
2.30.9