From b1c4dbc37375cd8151a963b8b81c929f9acdcdd9 Mon Sep 17 00:00:00 2001
From: Fabien Morin <fabien@nexedi.com>
Date: Fri, 27 Aug 2010 15:04:38 +0000
Subject: [PATCH] In multi relation field non editalbe mode, display link on
 each value in the field instead of the plane icon. This make much more easier
 to go on an element from the multi relation_field list (you don't need to go
 on the Jump Relation view to be able to select one value). The behaviour of
 editable multi relation fields (the most used in erp5) is not changed.

Reviewed by romain.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@38054 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5Form/MultiRelationField.py | 37 +++++++++++++++++++-------
 1 file changed, 28 insertions(+), 9 deletions(-)

diff --git a/product/ERP5Form/MultiRelationField.py b/product/ERP5Form/MultiRelationField.py
index d854bb4c6c..a9b66d4720 100644
--- a/product/ERP5Form/MultiRelationField.py
+++ b/product/ERP5Form/MultiRelationField.py
@@ -303,16 +303,35 @@ class MultiRelationStringFieldWidget(Widget.LinesTextAreaWidget,
   def render_view(self, field, value, REQUEST=None, render_prefix=None):
     """
     Render read only field.
-
-    XXX Improved rendering required
     """
-    html_string = self.default_widget_rendering_instance.render_view(
-                                                 field, value, REQUEST=REQUEST)
-    if REQUEST is None:
-      REQUEST = get_request()
-    relation_html_string = self.render_relation_link(field, value, REQUEST)
-    if relation_html_string != '':
-      html_string += '&nbsp;&nbsp;%s' % relation_html_string
+    html_string = ''
+    here = REQUEST['here']
+    portal_url = getToolByName(here, 'portal_url')
+    portal_url_string = portal_url()
+    if (value not in ((), [], None, '')) and \
+        field.get_value('allow_jump'):
+      string_list = []
+      base_category = field.get_value('base_category')
+      portal_type = map(lambda x:x[0],field.get_value('portal_type'))
+      kw = {}
+      for k, v in field.get_value('parameter_list') :
+        kw[k] = v
+      accessor_name = 'get%sValueList' % ''.join([part.capitalize() for part in base_category.split('_')])
+      jump_reference_list = getattr(here, accessor_name)(portal_type=portal_type, filter=kw)
+      if len(jump_reference_list):
+        for jump_reference in jump_reference_list:
+          string_list.append('<a href="%s">%s</a>' % \
+                  (jump_reference.absolute_url(),
+                   jump_reference.getTitle()))
+      html_string = '<br />'.join(string_list)
+    else:
+      html_string = self.default_widget_rendering_instance.render_view(field,
+          value, REQUEST=REQUEST)
+      if REQUEST is None:
+        REQUEST = get_request()
+      relation_html_string = self.render_relation_link(field, value, REQUEST)
+      if relation_html_string != '':
+        html_string += '&nbsp;&nbsp;%s' % relation_html_string
     return html_string
 
   def render_wheel(self, field, value, REQUEST, relation_index=0,
-- 
2.30.9