Commit 4e896323 authored by Georgios Dagkakis's avatar Georgios Dagkakis

SelectionTool/Listbox: Fix in calculating the start of last page in selection

Also, make sure that Listbox always knows how many lines are to be displayed.

Commit adds also testPagerWithCustomListMethod in listbox_zuite of erp5_ui_test,
which checks that listbox jumping to previous/next/first/last works
correctly in displaying the elements
parent f08c7dd1
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ZopePageTemplate" module="Products.PageTemplates.ZopePageTemplate"/>
</pickle>
<pickle>
<dictionary>
<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_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>text/html</string> </value>
</item>
<item>
<key> <string>expand</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>testPagerWithCustomListMethod</string> </value>
</item>
<item>
<key> <string>output_encoding</string> </key>
<value> <string>utf-8</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <unicode></unicode> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<html xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:metal="http://xml.zope.org/namespaces/metal">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Test Domain Tree</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">Test Previous/Next/First/Last page for custom list method</td></tr>
</thead><tbody>
<!-- Domain tree are not avalaible in mobile skin
So this part is skipped -->
<tal:block tal:condition="python: context.TestTool_getSkinName()!='Mobile'">
<tal:block metal:use-macro="here/ListBoxZuite_CommonTemplate/macros/init" />
<tr>
<td>open</td>
<td>${base_url}/ListBoxZuite_resetReportSelections</td>
<td></td>
</tr>
<tr>
<td>assertTextPresent</td>
<td>Done.</td>
<td></td>
</tr>
<!-- Land at first page -->
<tr>
<td>open</td>
<td>${base_url}/portal_skins/erp5_ui_test/Foo_viewDummyReturningOnlyWhatShownListBox</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>//a[.="A0"]</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>//a[.="A1"]</td>
<td></td>
</tr>
<!-- Go to next page -->
<tr>
<td>clickAndWait</td>
<td>//button[@class="listbox_next_page"]</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>//a[.="A2"]</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>//a[.="A3"]</td>
<td></td>
</tr>
<!-- Go to last page -->
<tr>
<td>clickAndWait</td>
<td>//button[@class="listbox_last_page"]</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>//a[.="A6"]</td>
<td></td>
</tr>
<!-- Go to last page -->
<tr>
<td>clickAndWait</td>
<td>//button[@class="listbox_previous_page"]</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>//a[.="A4"]</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>//a[.="A5"]</td>
<td></td>
</tr>
<!-- Go to first page -->
<tr>
<td>clickAndWait</td>
<td>//button[@class="listbox_first_page"]</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>//a[.="A0"]</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>//a[.="A1"]</td>
<td></td>
</tr>
</tal:block>
</tbody></table>
</body>
</html>
\ No newline at end of file
"""Returns a list of temp base objects"""
from Products.ERP5Type.Document import newTempBase
portal_object = context.getPortalObject()
limit = kw.get('limit')
list_start = int(kw.get('list_start', 0))
list_lines = int(kw.get('list_lines', 0))
size = list_lines or limit
result_list = []
result_list_append = result_list.append
for i in xrange(7):
if list_start < i + 1<= list_start + size:
caption = str(i)
result_list_append(newTempBase(portal_object, caption, a='A' + caption, b='B' + caption))
else:
result_list_append(None)
return result_list
<?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>*args, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Foo_getDummyReturningOnlyWhatShownListBoxLineList</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ERP5 Form" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<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/>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_objects</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>action</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string>Display a dummy listbox field for selenium tests</string> </value>
</item>
<item>
<key> <string>edit_order</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>encoding</string> </key>
<value> <string>UTF-8</string> </value>
</item>
<item>
<key> <string>enctype</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>group_list</string> </key>
<value>
<list>
<string>left</string>
<string>right</string>
<string>center</string>
<string>bottom</string>
<string>hidden</string>
</list>
</value>
</item>
<item>
<key> <string>groups</string> </key>
<value>
<dictionary>
<item>
<key> <string>bottom</string> </key>
<value>
<list>
<string>listbox</string>
</list>
</value>
</item>
<item>
<key> <string>center</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>hidden</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>left</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>right</string> </key>
<value>
<list/>
</value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Foo_viewDummyReturningOnlyWhatShownListBox</string> </value>
</item>
<item>
<key> <string>method</string> </key>
<value> <string>POST</string> </value>
</item>
<item>
<key> <string>name</string> </key>
<value> <string>Foo_viewDummyListBox</string> </value>
</item>
<item>
<key> <string>pt</string> </key>
<value> <string>form_view</string> </value>
</item>
<item>
<key> <string>row_length</string> </key>
<value> <int>4</int> </value>
</item>
<item>
<key> <string>stored_encoding</string> </key>
<value> <string>UTF-8</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Foo</string> </value>
</item>
<item>
<key> <string>unicode_mode</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>update_action</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
"""Reset report sleections""" """Reset report selections"""
manage_deleteSelection = context.getPortalObject().portal_selections.manage_deleteSelection manage_deleteSelection = context.getPortalObject().portal_selections.manage_deleteSelection
for index in xrange(3): for index in xrange(3):
...@@ -6,4 +6,8 @@ for index in xrange(3): ...@@ -6,4 +6,8 @@ for index in xrange(3):
manage_deleteSelection('x%s_foo_dummy_listbox_selection' % (index, )) manage_deleteSelection('x%s_foo_dummy_listbox_selection' % (index, ))
except KeyError: except KeyError:
pass pass
try:
manage_deleteSelection('foo_dummy_returning_only_what_is_shown_listbox_selection')
except KeyError:
pass
return "Done." return "Done."
...@@ -1931,6 +1931,11 @@ class ListBoxRenderer: ...@@ -1931,6 +1931,11 @@ class ListBoxRenderer:
report_section_list.append(ReportSection(is_summary = False, report_section_list.append(ReportSection(is_summary = False,
object_list_len = object_list_len - len(object_list) - start)) object_list_len = object_list_len - len(object_list) - start))
else: else:
if 'list_lines' not in param_dict:
# Let the list method know how many lines are to be shown,
# in case the selection is ran for first time
param_dict['list_lines'] = self.field.get_value('lines')
selection.edit(params=param_dict)
object_list = selection(method=domain_list_method, context=domain_context, REQUEST=self.request) object_list = selection(method=domain_list_method, context=domain_context, REQUEST=self.request)
object_list_len = len(object_list) object_list_len = len(object_list)
report_section_list.append(ReportSection(is_summary = False, report_section_list.append(ReportSection(is_summary = False,
...@@ -1966,6 +1971,7 @@ class ListBoxRenderer: ...@@ -1966,6 +1971,7 @@ class ListBoxRenderer:
# Calculuate the start and the end offsets, and set the page numbers. # Calculuate the start and the end offsets, and set the page numbers.
param_dict['list_lines'] = max_lines = self.getMaxLineNumber() param_dict['list_lines'] = max_lines = self.getMaxLineNumber()
param_dict['total_size'] = self.total_size
if max_lines: if max_lines:
start = end and end - 1 start = end and end - 1
self.total_pages = 1 + start // max_lines self.total_pages = 1 + start // max_lines
...@@ -1977,7 +1983,7 @@ class ListBoxRenderer: ...@@ -1977,7 +1983,7 @@ class ListBoxRenderer:
self.total_pages = 1 self.total_pages = 1
self.current_page = start = 0 self.current_page = start = 0
param_dict['list_start'] = start param_dict['list_start'] = start
self.getSelection().edit(params = param_dict) self.getSelection().edit(params=param_dict)
# Make a list of lines. # Make a list of lines.
line_class = self.getLineClass() line_class = self.getLineClass()
......
...@@ -743,9 +743,6 @@ class SelectionTool( BaseTool, SimpleItem ): ...@@ -743,9 +743,6 @@ class SelectionTool( BaseTool, SimpleItem ):
def firstPage(self, list_selection_name, listbox_uid, uids=None, REQUEST=None): def firstPage(self, list_selection_name, listbox_uid, uids=None, REQUEST=None):
""" """
Access the first page of a list Access the first page of a list
XXX: As its complementary (lastPage) is broken, this method is
probably not used either. If so, it should be removed along with
lastPage.
""" """
if uids is None: uids = [] if uids is None: uids = []
selection = self.getSelectionFor(list_selection_name, REQUEST) selection = self.getSelectionFor(list_selection_name, REQUEST)
...@@ -760,9 +757,6 @@ class SelectionTool( BaseTool, SimpleItem ): ...@@ -760,9 +757,6 @@ class SelectionTool( BaseTool, SimpleItem ):
def lastPage(self, list_selection_name, listbox_uid, uids=None, REQUEST=None): def lastPage(self, list_selection_name, listbox_uid, uids=None, REQUEST=None):
""" """
Access the last page of a list Access the last page of a list
XXX: This method is broken, since "total_size" field is not
present in the listbox rendering any longer. It should be
removed.
""" """
if uids is None: uids = [] if uids is None: uids = []
selection = self.getSelectionFor(list_selection_name, REQUEST) selection = self.getSelectionFor(list_selection_name, REQUEST)
...@@ -773,10 +767,17 @@ class SelectionTool( BaseTool, SimpleItem ): ...@@ -773,10 +767,17 @@ class SelectionTool( BaseTool, SimpleItem ):
# impossible. If you are in this case, send me a mail ! -- Kev # impossible. If you are in this case, send me a mail ! -- Kev
BIG_INT = 10000000 BIG_INT = 10000000
last_page_start = BIG_INT last_page_start = BIG_INT
total_lines = REQUEST.form.get('total_size', BIG_INT) total_lines = int(params.get('total_size', BIG_INT))
if total_lines != BIG_INT: if total_lines != BIG_INT:
lines_per_page = params.get('list_lines', 1) lines_per_page = int(params.get('list_lines', 1))
last_page_start = int(total_lines) - (int(total_lines) % int(lines_per_page)) if total_lines % lines_per_page:
# Example: if we have 105 documents and display 40 per line,
# it is 105 // 40 * 40 = 80
last_page_start = total_lines // lines_per_page * lines_per_page
else:
# Example; if we have 120 documents and display 40 per line,
# it is 120 // (40 - 1) * 40 = 80
last_page_start = (total_lines // lines_per_page - 1) * lines_per_page
params['list_start'] = last_page_start params['list_start'] = last_page_start
selection.edit(params=params) selection.edit(params=params)
self.uncheckAll(list_selection_name, listbox_uid) self.uncheckAll(list_selection_name, listbox_uid)
......
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