From f25d64f139141d5bfd413d5242103cc482c770da Mon Sep 17 00:00:00 2001
From: Tristan Cavelier <tristan.cavelier@nexedi.com>
Date: Mon, 30 May 2016 14:50:10 +0000
Subject: [PATCH] erp5_core: hot fix selection issue polluting listbox
 selection

1. go to an organisation
2. click on its listbox title
3. go back to the organisation
4. click on a person in the listbox
5. go back to the organisation - the listbox results changed because of polluted selection
---
 .../Base_getViewModeListboxSelectionName.py   | 17 +++++
 .../Base_getViewModeListboxSelectionName.xml  | 62 +++++++++++++++++++
 .../my_view_mode_listbox.xml                  |  2 +-
 3 files changed, 80 insertions(+), 1 deletion(-)
 create mode 100644 product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Base_getViewModeListboxSelectionName.py
 create mode 100644 product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Base_getViewModeListboxSelectionName.xml

diff --git a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Base_getViewModeListboxSelectionName.py b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Base_getViewModeListboxSelectionName.py
new file mode 100644
index 0000000000..93b0f4ebc9
--- /dev/null
+++ b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Base_getViewModeListboxSelectionName.py
@@ -0,0 +1,17 @@
+if REQUEST is None or form.getId() != "Base_viewListModeRenderer":
+  return "%s_%s_selection" % (form.getId(), field.getId())
+
+request_selection_name = REQUEST.get("selection_name")
+if request_selection_name:
+  selection_parameters = context.portal_selections.getSelectionParamsFor("%s_list_mode_proxy_selection" % request_selection_name)
+else:
+  selection_parameters = {}
+
+return "%s_%s_selection" % (
+  REQUEST.get("proxy_form_id") or
+  selection_parameters.get("proxy_form_id") or
+  form.getId(),
+  REQUEST.get("proxy_field_id") or
+  selection_parameters.get("proxy_field_id") or
+  field.getId(),
+)
diff --git a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Base_getViewModeListboxSelectionName.xml b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Base_getViewModeListboxSelectionName.xml
new file mode 100644
index 0000000000..6ac3e52cb6
--- /dev/null
+++ b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Base_getViewModeListboxSelectionName.xml
@@ -0,0 +1,62 @@
+<?xml version="1.0"?>
+<ZopeData>
+  <record id="1" aka="AAAAAAAAAAE=">
+    <pickle>
+      <global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <item>
+            <key> <string>Script_magic</string> </key>
+            <value> <int>3</int> </value>
+        </item>
+        <item>
+            <key> <string>_bind_names</string> </key>
+            <value>
+              <object>
+                <klass>
+                  <global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
+                </klass>
+                <tuple/>
+                <state>
+                  <dictionary>
+                    <item>
+                        <key> <string>_asgns</string> </key>
+                        <value>
+                          <dictionary>
+                            <item>
+                                <key> <string>name_container</string> </key>
+                                <value> <string>container</string> </value>
+                            </item>
+                            <item>
+                                <key> <string>name_context</string> </key>
+                                <value> <string>context</string> </value>
+                            </item>
+                            <item>
+                                <key> <string>name_m_self</string> </key>
+                                <value> <string>script</string> </value>
+                            </item>
+                            <item>
+                                <key> <string>name_subpath</string> </key>
+                                <value> <string>traverse_subpath</string> </value>
+                            </item>
+                          </dictionary>
+                        </value>
+                    </item>
+                  </dictionary>
+                </state>
+              </object>
+            </value>
+        </item>
+        <item>
+            <key> <string>_params</string> </key>
+            <value> <string>form, field, REQUEST=None</string> </value>
+        </item>
+        <item>
+            <key> <string>id</string> </key>
+            <value> <string>Base_getViewModeListboxSelectionName</string> </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+</ZopeData>
diff --git a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Base_viewFieldLibrary/my_view_mode_listbox.xml b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Base_viewFieldLibrary/my_view_mode_listbox.xml
index 80c0601cbf..cbcef403bf 100644
--- a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Base_viewFieldLibrary/my_view_mode_listbox.xml
+++ b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Base_viewFieldLibrary/my_view_mode_listbox.xml
@@ -603,7 +603,7 @@ string:Base_viewListMode?proxy_form_id=${form/getId}&proxy_field_id=${field/getI
       <dictionary>
         <item>
             <key> <string>_text</string> </key>
-            <value> <string>python: \'%s_%s_selection\' % (request.get("proxy_form_id") or context.portal_selections.getSelectionParamsFor(\'%s_list_mode_proxy_selection\' % context.REQUEST.get(\'selection_name\', \'\')).get(\'proxy_form_id\') or form.getId(), request.get("proxy_field_id") or context.portal_selections.getSelectionParamsFor(\'%s_list_mode_proxy_selection\' % context.REQUEST.get(\'selection_name\', \'\')).get(\'proxy_field_id\') or field.getId())</string> </value>
+            <value> <string>python: context.Base_getViewModeListboxSelectionName(form=form, field=field, REQUEST=request)</string> </value>
         </item>
       </dictionary>
     </pickle>
-- 
2.30.9