Commit ce59055f authored by Julien Muchembled's avatar Julien Muchembled

ERP5Form: fix autojump to a previous listbox page when the number of lines decreases

parent 73c265ce
...@@ -1014,9 +1014,6 @@ class ListBoxRenderer: ...@@ -1014,9 +1014,6 @@ class ListBoxRenderer:
list_action_part_list.append('&ignore_layout:int=1') list_action_part_list.append('&ignore_layout:int=1')
return ''.join(list_action_part_list) return ''.join(list_action_part_list)
# Whether the selection object is initialized.
is_selection_initialized = False
@lazyMethod @lazyMethod
def getSelection(self): def getSelection(self):
"""FIXME: Tweak a selection and return the selection object. """FIXME: Tweak a selection and return the selection object.
...@@ -1028,9 +1025,6 @@ class ListBoxRenderer: ...@@ -1028,9 +1025,6 @@ class ListBoxRenderer:
selection_name = self.getSelectionName() selection_name = self.getSelectionName()
selection = selection_tool.getSelectionFor(selection_name, REQUEST = self.request) selection = selection_tool.getSelectionFor(selection_name, REQUEST = self.request)
if self.is_selection_initialized:
return selection
# Create a selection, if not present, with the default sort order. # Create a selection, if not present, with the default sort order.
if selection is None: if selection is None:
selection = Selection(selection_name, selection = Selection(selection_name,
...@@ -1061,8 +1055,6 @@ class ListBoxRenderer: ...@@ -1061,8 +1055,6 @@ class ListBoxRenderer:
is_report_opened = self.request.get('is_report_opened', selection.isReportOpened()) is_report_opened = self.request.get('is_report_opened', selection.isReportOpened())
selection.edit(report_opened = is_report_opened) selection.edit(report_opened = is_report_opened)
self.is_selection_initialized = True
return selection return selection
@lazyMethod @lazyMethod
...@@ -1958,8 +1950,6 @@ class ListBoxRenderer: ...@@ -1958,8 +1950,6 @@ class ListBoxRenderer:
"""Get report sections and construct a list of lines. Note that this method has a side """Get report sections and construct a list of lines. Note that this method has a side
effect in the selection, and the renderer object itself. effect in the selection, and the renderer object itself.
""" """
start = self.getLineStart()
max_lines = self.getMaxLineNumber()
if self.isHideRowsOnNoSearchCriterion(): if self.isHideRowsOnNoSearchCriterion():
report_section_list = [] report_section_list = []
else: else:
...@@ -1967,28 +1957,26 @@ class ListBoxRenderer: ...@@ -1967,28 +1957,26 @@ class ListBoxRenderer:
param_dict = self.getParamDict() param_dict = self.getParamDict()
# Set the total number of objects. # Set the total number of objects.
self.total_size = sum([s.object_list_len for s in report_section_list]) self.total_size = end = sum(s.object_list_len for s in report_section_list)
limit = param_dict.get('limit') limit = param_dict.get('limit')
if isinstance(limit, basestring): if isinstance(limit, basestring):
limit = int(limit) limit = int(limit)
self.is_sample = self.total_size == limit self.is_sample = end == limit
# Calculuate the start and the end offsets, and set the page numbers. # Calculuate the start and the end offsets, and set the page numbers.
if max_lines == 0: param_dict['list_lines'] = max_lines = self.getMaxLineNumber()
end = self.total_size if max_lines:
self.total_pages = 1 start = end and end - 1
self.current_page = 0 self.total_pages = 1 + start // max_lines
start = min(start, self.getLineStart())
start -= start % max_lines
end = min(start + max_lines, end)
self.current_page = start // max_lines
else: else:
self.total_pages = int(max(self.total_size - 1, 0) / max_lines) + 1 self.total_pages = 1
if start >= self.total_size: self.current_page = start = 0
start = max(self.total_size - 1, 0) param_dict['list_start'] = start
start -= (start % max_lines) self.getSelection().edit(params = param_dict)
self.current_page = int(start / max_lines)
end = min(start + max_lines, self.total_size)
param_dict['list_start'] = start
param_dict['list_lines'] = max_lines
selection = self.getSelection()
selection.edit(params = param_dict)
# Make a list of lines. # Make a list of lines.
line_class = self.getLineClass() line_class = self.getLineClass()
...@@ -1999,7 +1987,7 @@ class ListBoxRenderer: ...@@ -1999,7 +1987,7 @@ class ListBoxRenderer:
current_section_base_index = 0 current_section_base_index = 0
current_section = report_section_list[0] current_section = report_section_list[0]
current_section_size = current_section.object_list_len current_section_size = current_section.object_list_len
for i in range(start, end): for i in xrange(start, end):
# Make sure we go to the right section. # Make sure we go to the right section.
while current_section_base_index + current_section_size <= i: while current_section_base_index + current_section_size <= i:
current_section_base_index += current_section_size current_section_base_index += current_section_size
...@@ -2015,8 +2003,7 @@ class ListBoxRenderer: ...@@ -2015,8 +2003,7 @@ class ListBoxRenderer:
else: else:
index = i index = i
#LOG('ListBox', 0, 'current_section.__dict__ = %r' % (current_section.__dict__,)) #LOG('ListBox', 0, 'current_section.__dict__ = %r' % (current_section.__dict__,))
if 'total_size' in param_dict.keys(): param_dict.pop('total_size', None)
param_dict.pop('total_size')
row_css_class_name = self.getRowCSSClassName( row_css_class_name = self.getRowCSSClassName(
brain=current_section.object_list[offset], brain=current_section.object_list[offset],
field=self.field, field=self.field,
...@@ -2510,7 +2497,6 @@ class ListBoxHTMLRenderer(ListBoxRenderer): ...@@ -2510,7 +2497,6 @@ class ListBoxHTMLRenderer(ListBoxRenderer):
""" """
return ListBoxHTMLRendererLine return ListBoxHTMLRendererLine
@lazyMethod
def getLineStart(self): def getLineStart(self):
"""Return a requested start number. """Return a requested start number.
""" """
......
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