Commit 1fe07663 authored by Jérome Perrin's avatar Jérome Perrin

diff_tool: fix comparison order when "compare two objects"

This was comparing the two selected documents in random order, which
caused some test failures sometimes but also was not user friendly. Now
the oldest should always be on the left and newest on the right.

Also drop Base_getObjectPathFromSelection which became not used.
parent e8c0e1cd
......@@ -2,12 +2,12 @@
xmlns:metal="http://xml.zope.org/namespaces/metal">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Test Generic Search Dialog</title>
<title>Test Diff Action on Module</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">Test Portal Diff<tal:block metal:use-macro="here/Zuite_CommonTemplate/macros/expected_failure_for_anonymous_selection" /></td></tr>
<tr><td rowspan="1" colspan="3">Test Diff Action on Module<tal:block metal:use-macro="here/Zuite_CommonTemplate/macros/expected_failure_for_anonymous_selection" /></td></tr>
</thead><tbody>
<tal:block metal:use-macro="here/PTZuite_CommonTemplate/macros/init" />
<tr>
......@@ -67,12 +67,12 @@
<tr>
<td>verifyValue</td>
<td>field_your_first_path</td>
<td>bar_module/2</td>
<td>bar_module/1</td>
</tr>
<tr>
<td>verifyValue</td>
<td>field_your_second_path</td>
<td>bar_module/1</td>
<td>bar_module/2</td>
</tr>
<tr>
......@@ -103,7 +103,7 @@
<tr>
<td>verifyEval</td>
<td>storedVars['_data_gadget_value'].replace(/(\r\n\t|\n|\r\t)/gm,"").replace(/\s+/g, '')</td>
<td>---+++@@-1+1@@-Title2+Title1</td>
<td>---+++@@-1+1@@-Title1+Title2</td>
</tr>
</body>
......
portal = context.getPortalObject()
# There would be multiple cases where this script will be called, but the only
# case where we use selections to get the diff. Hence, we check for the condition
# that list_selection_name is not None.
if list_selection_name is not None:
# Get the selcted values for the web page selection
selected_obj_list = portal.portal_selections.getSelectionCheckedValueList(selection_name=list_selection_name)
# Return the 1st object path from the selected_obj_list
return selected_obj_list[selection_index].getRelativeUrl()
<?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>selection_index, list_selection_name=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_getObjectPathFromSelection</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -19,6 +19,9 @@ if list_selection_name is not None:
message = context.Base_translateString("This action can only compare exactly 2 objects.")
return context.Base_redirect('view', keep_items={'portal_status_message': message})
else:
# Compare "oldest" with "newest"
selected_obj_list = [x.getObject() for x in selected_obj_list]
selected_obj_list = sorted(selected_obj_list, key=lambda x: x.getCreationDate())
# Keep the `list_selection_name` in keep_items as we will be needing it
# while displaying the paths of the selected objects.
return context.Base_redirect('ERP5Site_viewDiffTwoObjectDialog',
......
......@@ -122,7 +122,7 @@
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python: context.Base_getObjectPathFromSelection(0, list_selection_name=REQUEST.get(\'list_selection_name\', None))</string> </value>
<value> <string>request/your_first_path | nothing</string> </value>
</item>
</dictionary>
</pickle>
......
......@@ -122,7 +122,7 @@
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python: context.Base_getObjectPathFromSelection(1, list_selection_name=REQUEST.get(\'list_selection_name\', None))</string> </value>
<value> <string>request/your_second_path | nothing</string> </value>
</item>
</dictionary>
</pickle>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment