From 300661472e95ef8f3f1cb2efdd10a301da4198ee Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com>
Date: Tue, 1 Jul 2014 17:17:35 +0200
Subject: [PATCH] test_result: Rewrite TestResultLine_viewResultHistory

so that test result line does not need to be indexable
---
 .../TestResultLine_countResultHistoryList.xml | 76 +++++++++++++++++++
 .../TestResultLine_getResultHistoryList.xml   | 34 +++++++--
 .../listbox.xml                               | 50 ++++++++++--
 3 files changed, 147 insertions(+), 13 deletions(-)
 create mode 100644 bt5/erp5_test_result/SkinTemplateItem/portal_skins/erp5_test_result/TestResultLine_countResultHistoryList.xml

diff --git a/bt5/erp5_test_result/SkinTemplateItem/portal_skins/erp5_test_result/TestResultLine_countResultHistoryList.xml b/bt5/erp5_test_result/SkinTemplateItem/portal_skins/erp5_test_result/TestResultLine_countResultHistoryList.xml
new file mode 100644
index 0000000000..c52fc8c45a
--- /dev/null
+++ b/bt5/erp5_test_result/SkinTemplateItem/portal_skins/erp5_test_result/TestResultLine_countResultHistoryList.xml
@@ -0,0 +1,76 @@
+<?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>_body</string> </key>
+            <value> <string>"""Count all previous test result line for the same test, same\n
+test suite, but for older revisions.\n
+"""\n
+\n
+test_result = context.getParentValue()\n
+query_params = {\'portal_type\': \'Test Result\',\n
+                \'title\': dict(query=test_result.getTitle(), key=\'ExactMatch\'),\n
+                \'simulation_state\': (\'stopped\', \'public_stopped\', \'failed\'),\n
+                }\n
+return context.portal_catalog.countResults(**query_params)\n
+</string> </value>
+        </item>
+        <item>
+            <key> <string>_params</string> </key>
+            <value> <string>**kw</string> </value>
+        </item>
+        <item>
+            <key> <string>id</string> </key>
+            <value> <string>TestResultLine_countResultHistoryList</string> </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+</ZopeData>
diff --git a/bt5/erp5_test_result/SkinTemplateItem/portal_skins/erp5_test_result/TestResultLine_getResultHistoryList.xml b/bt5/erp5_test_result/SkinTemplateItem/portal_skins/erp5_test_result/TestResultLine_getResultHistoryList.xml
index 6f045dcc0e..8dccf80f83 100644
--- a/bt5/erp5_test_result/SkinTemplateItem/portal_skins/erp5_test_result/TestResultLine_getResultHistoryList.xml
+++ b/bt5/erp5_test_result/SkinTemplateItem/portal_skins/erp5_test_result/TestResultLine_getResultHistoryList.xml
@@ -58,19 +58,41 @@ Note that creation_date is used, but it could be nicer to use\n
 the start date. However for now it is more convenient from a\n
 catalog point of view\n
 """\n
+\n
 test_result = context.getParentValue()\n
+\n
 query_params = {\'creation_date\' : dict(query=context.getCreationDate(), range=\'ngt\'),\n
-                \'portal_type\': context.getPortalType(),\n
-                \'title\': dict(query=context.getTitle(), key=\'ExactMatch\'),\n
-                \'parent_title\': dict(query=test_result.getTitle(), key=\'ExactMatch\'),\n
-                \'simulation_state\': \'stopped\',\n
+                \'portal_type\': \'Test Result\',\n
+                \'limit\': limit,\n
+                \'title\': dict(query=test_result.getTitle(), key=\'ExactMatch\'),\n
+                \'simulation_state\': (\'stopped\', \'public_stopped\', \'failed\'),\n
                 \'sort_on\': ((\'creation_date\', \'descending\'),),}\n
-return context.portal_catalog(**query_params)\n
+\n
+result_list = []\n
+expected_id = context.getId()\n
+expected_title = context.getTitle()\n
+for tr in context.portal_catalog(**query_params):\n
+  tr = tr.getObject()\n
+  # Optimisation: the test result line probably have the same id in the previous\n
+  # test result.\n
+  line = getattr(tr, expected_id, None)\n
+  if line is not None and line.getTitle() == expected_title \\\n
+      and line.getSimulationState() in (\'stopped\', \'public_stopped\', \'failed\'):\n
+    result_list.append(line)\n
+  else:\n
+    for line in tr.contentValues(portal_type=\'Test Result Line\'):\n
+      if line.getTitle() == context.getTitle() \\\n
+         and line.getSimulationState() in (\'stopped\', \'public_stopped\', \'failed\'):\n
+        result_list.append(line)\n
+        # next time, the test result line will likely have the same id as this one.\n
+        expected_id = line.getId()\n
+\n
+return result_list\n
 </string> </value>
         </item>
         <item>
             <key> <string>_params</string> </key>
-            <value> <string>**kw</string> </value>
+            <value> <string>limit, **kw</string> </value>
         </item>
         <item>
             <key> <string>id</string> </key>
diff --git a/bt5/erp5_test_result/SkinTemplateItem/portal_skins/erp5_test_result/TestResultLine_viewResultHistory/listbox.xml b/bt5/erp5_test_result/SkinTemplateItem/portal_skins/erp5_test_result/TestResultLine_viewResultHistory/listbox.xml
index 697984dad7..7385835d35 100644
--- a/bt5/erp5_test_result/SkinTemplateItem/portal_skins/erp5_test_result/TestResultLine_viewResultHistory/listbox.xml
+++ b/bt5/erp5_test_result/SkinTemplateItem/portal_skins/erp5_test_result/TestResultLine_viewResultHistory/listbox.xml
@@ -394,12 +394,18 @@
                 </item>
                 <item>
                     <key> <string>count_method</string> </key>
-                    <value> <string></string> </value>
+                    <value>
+                      <persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
+                    </value>
                 </item>
                 <item>
                     <key> <string>css_class</string> </key>
                     <value> <string></string> </value>
                 </item>
+                <item>
+                    <key> <string>default_display_style</string> </key>
+                    <value> <string>table</string> </value>
+                </item>
                 <item>
                     <key> <string>default_params</string> </key>
                     <value>
@@ -410,6 +416,12 @@
                     <key> <string>description</string> </key>
                     <value> <string></string> </value>
                 </item>
+                <item>
+                    <key> <string>display_style_list</string> </key>
+                    <value>
+                      <list/>
+                    </value>
+                </item>
                 <item>
                     <key> <string>domain_root_list</string> </key>
                     <value>
@@ -449,6 +461,10 @@
                       <list/>
                     </value>
                 </item>
+                <item>
+                    <key> <string>global_search_column</string> </key>
+                    <value> <string></string> </value>
+                </item>
                 <item>
                     <key> <string>hidden</string> </key>
                     <value> <int>0</int> </value>
@@ -459,7 +475,7 @@
                 </item>
                 <item>
                     <key> <string>lines</string> </key>
-                    <value> <int>20</int> </value>
+                    <value> <int>15</int> </value>
                 </item>
                 <item>
                     <key> <string>list_action</string> </key>
@@ -468,7 +484,7 @@
                 <item>
                     <key> <string>list_method</string> </key>
                     <value>
-                      <persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
+                      <persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
                     </value>
                 </item>
                 <item>
@@ -477,6 +493,10 @@
                       <list/>
                     </value>
                 </item>
+                <item>
+                    <key> <string>page_navigation_template</string> </key>
+                    <value> <string>ListBox_viewSliderPageNavigationRenderer</string> </value>
+                </item>
                 <item>
                     <key> <string>page_template</string> </key>
                     <value> <string></string> </value>
@@ -541,6 +561,12 @@
                     <key> <string>stat_method</string> </key>
                     <value> <string></string> </value>
                 </item>
+                <item>
+                    <key> <string>style_columns</string> </key>
+                    <value>
+                      <list/>
+                    </value>
+                </item>
                 <item>
                     <key> <string>title</string> </key>
                     <value> <string>listbox</string> </value>
@@ -565,10 +591,20 @@
   </record>
   <record id="2" aka="AAAAAAAAAAI=">
     <pickle>
-      <tuple>
-        <global name="Method" module="Products.Formulator.MethodField"/>
-        <tuple/>
-      </tuple>
+      <global name="Method" module="Products.Formulator.MethodField"/>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <item>
+            <key> <string>method_name</string> </key>
+            <value> <string>TestResultLine_countResultHistoryList</string> </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+  <record id="3" aka="AAAAAAAAAAM=">
+    <pickle>
+      <global name="Method" module="Products.Formulator.MethodField"/>
     </pickle>
     <pickle>
       <dictionary>
-- 
2.30.9