Commit 0af640e1 authored by Kevin Deldycke's avatar Kevin Deldycke

Add two new listbox related method to get the first page and the last page of...

Add two new listbox related method to get the first page and the last page of a multiple-page listbox.
Auto-delete of trailing spaces.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@8679 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 9eaeb22a
...@@ -26,8 +26,8 @@ ...@@ -26,8 +26,8 @@
# #
############################################################################## ##############################################################################
"""\ """
ERP portal_selection tool. ERP5 portal_selection tool.
""" """
from OFS.Traversable import NotFound from OFS.Traversable import NotFound
...@@ -210,11 +210,11 @@ class SelectionTool( UniqueObject, SimpleItem ): ...@@ -210,11 +210,11 @@ class SelectionTool( UniqueObject, SimpleItem ):
return params return params
else: else:
return params return params
# backward compatibility # backward compatibility
security.declareProtected(ERP5Permissions.View, 'getSelectionParams') security.declareProtected(ERP5Permissions.View, 'getSelectionParams')
getSelectionParams = getSelectionParamsFor getSelectionParams = getSelectionParamsFor
security.declareProtected(ERP5Permissions.View, 'setSelectionParamsFor') security.declareProtected(ERP5Permissions.View, 'setSelectionParamsFor')
def setSelectionParamsFor(self, selection_name, params, REQUEST=None): def setSelectionParamsFor(self, selection_name, params, REQUEST=None):
""" """
...@@ -504,6 +504,48 @@ class SelectionTool( UniqueObject, SimpleItem ): ...@@ -504,6 +504,48 @@ class SelectionTool( UniqueObject, SimpleItem ):
# ListBox related methods # ListBox related methods
security.declareProtected(ERP5Permissions.View, 'firstPage')
def firstPage(self, listbox_uid, uids=None, REQUEST=None):
"""
Access the first page of a list
"""
if uids is None: uids = []
request = REQUEST
#form_id = request.form_id
selection_name = request.list_selection_name
selection = self.getSelectionFor(selection_name, REQUEST)
params = selection.getParams()
params['list_start'] = 0
selection.edit(params=params)
self.uncheckAll(selection_name, listbox_uid)
return self.checkAll(selection_name, uids, REQUEST=REQUEST)
security.declareProtected(ERP5Permissions.View, 'lastPage')
def lastPage(self, listbox_uid, uids=None, REQUEST=None):
"""
Access the last page of a list
"""
if uids is None: uids = []
request = REQUEST
#form_id = request.form_id
selection_name = request.list_selection_name
selection = self.getSelectionFor(selection_name, REQUEST)
params = selection.getParams()
# XXX This will not work if the number of lines shown in the listbox is greater
# than the BIG_INT constan. Such a case has low probability but is not
# impossible. If you are in this case, send me a mail ! -- Kev
BIG_INT = 10000000
last_page_start = BIG_INT
total_lines = request.form.get('total_size', BIG_INT)
if total_lines != BIG_INT:
lines_per_page = params.get('list_lines', 1)
last_page_start = int(total_lines) - (int(total_lines) % int(lines_per_page))
params['list_start'] = last_page_start
selection.edit(params=params)
self.uncheckAll(selection_name, listbox_uid)
return self.checkAll(selection_name, uids, REQUEST=REQUEST)
security.declareProtected(ERP5Permissions.View, 'nextPage') security.declareProtected(ERP5Permissions.View, 'nextPage')
def nextPage(self, listbox_uid, uids=None, REQUEST=None): def nextPage(self, listbox_uid, uids=None, REQUEST=None):
""" """
...@@ -518,8 +560,7 @@ class SelectionTool( UniqueObject, SimpleItem ): ...@@ -518,8 +560,7 @@ class SelectionTool( UniqueObject, SimpleItem ):
lines = params.get('list_lines',0) lines = params.get('list_lines',0)
start = params.get('list_start', 0) start = params.get('list_start', 0)
params['list_start'] = int(start) + int(lines) params['list_start'] = int(start) + int(lines)
selection.edit(params= params) selection.edit(params=params)
self.uncheckAll(selection_name, listbox_uid) self.uncheckAll(selection_name, listbox_uid)
return self.checkAll(selection_name, uids, REQUEST=REQUEST) return self.checkAll(selection_name, uids, REQUEST=REQUEST)
...@@ -537,8 +578,7 @@ class SelectionTool( UniqueObject, SimpleItem ): ...@@ -537,8 +578,7 @@ class SelectionTool( UniqueObject, SimpleItem ):
lines = params.get('list_lines',0) lines = params.get('list_lines',0)
start = params.get('list_start', 0) start = params.get('list_start', 0)
params['list_start'] = max(int(start) - int(lines), 0) params['list_start'] = max(int(start) - int(lines), 0)
selection.edit(params= selection.params) selection.edit(params=selection.params)
self.uncheckAll(selection_name, listbox_uid) self.uncheckAll(selection_name, listbox_uid)
return self.checkAll(selection_name, uids, REQUEST=REQUEST) return self.checkAll(selection_name, uids, REQUEST=REQUEST)
...@@ -551,21 +591,19 @@ class SelectionTool( UniqueObject, SimpleItem ): ...@@ -551,21 +591,19 @@ class SelectionTool( UniqueObject, SimpleItem ):
request = REQUEST request = REQUEST
#form_id = request.form_id #form_id = request.form_id
selection_name = request.list_selection_name selection_name = request.list_selection_name
selection = self.getSelectionFor(selection_name, REQUEST=REQUEST) selection = self.getSelectionFor(selection_name, REQUEST=REQUEST)
if selection is not None: if selection is not None:
params = selection.getParams() params = selection.getParams()
lines = params.get('list_lines',0) lines = params.get('list_lines',0)
start = request.form.get('list_start',0) start = request.form.get('list_start',0)
params['list_start'] = start params['list_start'] = start
selection.edit(params= selection.params) selection.edit(params= selection.params)
self.uncheckAll(selection_name, listbox_uid) self.uncheckAll(selection_name, listbox_uid)
return self.checkAll(selection_name, uids, REQUEST=REQUEST, query_string=query_string) return self.checkAll(selection_name, uids, REQUEST=REQUEST, query_string=query_string)
# PlanningBox related methods # PlanningBox related methods
security.declareProtected(ERP5Permissions.View, 'setZoomLevel') security.declareProtected(ERP5Permissions.View, 'setZoomLevel')
def setZoomLevel(self, uids=None, REQUEST=None): def setZoomLevel(self, uids=None, REQUEST=None):
""" """
...@@ -749,7 +787,7 @@ class SelectionTool( UniqueObject, SimpleItem ): ...@@ -749,7 +787,7 @@ class SelectionTool( UniqueObject, SimpleItem ):
return 'FlatListMode' return 'FlatListMode'
security.declareProtected(ERP5Permissions.View, 'setListboxDisplayMode') security.declareProtected(ERP5Permissions.View, 'setListboxDisplayMode')
def setListboxDisplayMode(self, REQUEST, listbox_display_mode, def setListboxDisplayMode(self, REQUEST, listbox_display_mode,
selection_name=None, redirect=0, selection_name=None, redirect=0,
form_id=None, query_string=None): form_id=None, query_string=None):
""" """
...@@ -763,8 +801,8 @@ class SelectionTool( UniqueObject, SimpleItem ): ...@@ -763,8 +801,8 @@ class SelectionTool( UniqueObject, SimpleItem ):
# This need to be cleaned # This need to be cleaned
# Beware, this fix may break the report system... # Beware, this fix may break the report system...
# and we don't have test for this # and we don't have test for this
# Possible fix: currently, display mode icon are implemented as # Possible fix: currently, display mode icon are implemented as
# method. It could be easier to generate them as link (where we # method. It could be easier to generate them as link (where we
# can define explicitely parameters through the url). # can define explicitely parameters through the url).
try: try:
list_selection_name = request.list_selection_name list_selection_name = request.list_selection_name
...@@ -794,7 +832,7 @@ class SelectionTool( UniqueObject, SimpleItem ): ...@@ -794,7 +832,7 @@ class SelectionTool( UniqueObject, SimpleItem ):
else: else:
flat_list_mode = 0 flat_list_mode = 0
domain_tree_mode = 0 domain_tree_mode = 0
report_tree_mode = 0 report_tree_mode = 0
selection.edit(flat_list_mode=flat_list_mode, selection.edit(flat_list_mode=flat_list_mode,
domain_tree_mode=domain_tree_mode, domain_tree_mode=domain_tree_mode,
...@@ -815,7 +853,7 @@ class SelectionTool( UniqueObject, SimpleItem ): ...@@ -815,7 +853,7 @@ class SelectionTool( UniqueObject, SimpleItem ):
Set display of the listbox to FlatList mode Set display of the listbox to FlatList mode
""" """
return self.setListboxDisplayMode( return self.setListboxDisplayMode(
REQUEST=REQUEST, listbox_display_mode='FlatListMode', REQUEST=REQUEST, listbox_display_mode='FlatListMode',
selection_name=selection_name, redirect=1) selection_name=selection_name, redirect=1)
security.declareProtected(ERP5Permissions.View, 'setDomainTreeMode') security.declareProtected(ERP5Permissions.View, 'setDomainTreeMode')
...@@ -824,7 +862,7 @@ class SelectionTool( UniqueObject, SimpleItem ): ...@@ -824,7 +862,7 @@ class SelectionTool( UniqueObject, SimpleItem ):
Set display of the listbox to DomainTree mode Set display of the listbox to DomainTree mode
""" """
return self.setListboxDisplayMode( return self.setListboxDisplayMode(
REQUEST=REQUEST, listbox_display_mode='DomainTreeMode', REQUEST=REQUEST, listbox_display_mode='DomainTreeMode',
selection_name=selection_name, redirect=1) selection_name=selection_name, redirect=1)
security.declareProtected(ERP5Permissions.View, 'setReportTreeMode') security.declareProtected(ERP5Permissions.View, 'setReportTreeMode')
...@@ -867,8 +905,8 @@ class SelectionTool( UniqueObject, SimpleItem ): ...@@ -867,8 +905,8 @@ class SelectionTool( UniqueObject, SimpleItem ):
if len(value_list) == 0: if len(value_list) == 0:
value_list = self.getSelectionSelectedValueList( value_list = self.getSelectionSelectedValueList(
selection_name, selection_name,
REQUEST=REQUEST, REQUEST=REQUEST,
selection_method=selection_method, selection_method=selection_method,
context=context) context=context)
return value_list return value_list
...@@ -885,7 +923,7 @@ class SelectionTool( UniqueObject, SimpleItem ): ...@@ -885,7 +923,7 @@ class SelectionTool( UniqueObject, SimpleItem ):
We want to be sure that the selection did not change We want to be sure that the selection did not change
""" """
# XXX To avoid the difference of the string representations of int and long, # XXX To avoid the difference of the string representations of int and long,
# convert each element to a string. # convert each element to a string.
object_uid_list = [str(x) for x in object_uid_list] object_uid_list = [str(x) for x in object_uid_list]
object_uid_list.sort() object_uid_list.sort()
new_md5_string = md5.new(str(object_uid_list)).hexdigest() new_md5_string = md5.new(str(object_uid_list)).hexdigest()
...@@ -1071,10 +1109,10 @@ class SelectionTool( UniqueObject, SimpleItem ): ...@@ -1071,10 +1109,10 @@ class SelectionTool( UniqueObject, SimpleItem ):
# Checked current uid # Checked current uid
kw ={} kw ={}
kw[field.get_value('catalog_index')] = field_value kw[field.get_value('catalog_index')] = field_value
self.portal_selections.setSelectionParamsFor(selection_name, self.portal_selections.setSelectionParamsFor(selection_name,
kw.copy()) kw.copy())
self.portal_selections.setSelectionCheckedUidsFor( self.portal_selections.setSelectionCheckedUidsFor(
selection_name, selection_name,
current_uid_list) current_uid_list)
field_value = str(field_value).splitlines() field_value = str(field_value).splitlines()
REQUEST.form[field_key] = field_value REQUEST.form[field_key] = field_value
...@@ -1112,7 +1150,7 @@ class SelectionTool( UniqueObject, SimpleItem ): ...@@ -1112,7 +1150,7 @@ class SelectionTool( UniqueObject, SimpleItem ):
kw['previous_form_id'] = form_id kw['previous_form_id'] = form_id
kw[field.get_value('catalog_index')] = field_value kw[field.get_value('catalog_index')] = field_value
kw['portal_status_message'] = portal_status_message kw['portal_status_message'] = portal_status_message
kw['form_pickle'] = form_pickle kw['form_pickle'] = form_pickle
kw['form_signature'] = form_signature kw['form_signature'] = form_signature
# Empty the selection (uid) # Empty the selection (uid)
...@@ -1125,7 +1163,7 @@ class SelectionTool( UniqueObject, SimpleItem ): ...@@ -1125,7 +1163,7 @@ class SelectionTool( UniqueObject, SimpleItem ):
def _aq_dynamic(self, name): def _aq_dynamic(self, name):
""" """
Generate viewSearchRelatedDocumentDialog0, Generate viewSearchRelatedDocumentDialog0,
viewSearchRelatedDocumentDialog1,... if necessary viewSearchRelatedDocumentDialog1,... if necessary
""" """
aq_base_name = getattr(aq_base(self), name, None) aq_base_name = getattr(aq_base(self), name, None)
...@@ -1154,17 +1192,17 @@ class SelectionTool( UniqueObject, SimpleItem ): ...@@ -1154,17 +1192,17 @@ class SelectionTool( UniqueObject, SimpleItem ):
sub_index = None sub_index = None
# generate dynamicaly needed forwarder methods # generate dynamicaly needed forwarder methods
def viewSearchRelatedDocumentDialogWrapper(self, form_id, def viewSearchRelatedDocumentDialogWrapper(self, form_id,
REQUEST=None, **kw): REQUEST=None, **kw):
""" """
viewSearchRelatedDocumentDialog Wrapper viewSearchRelatedDocumentDialog Wrapper
""" """
LOG('SelectionTool.viewSearchRelatedDocumentDialogWrapper, kw', LOG('SelectionTool.viewSearchRelatedDocumentDialogWrapper, kw',
0, kw) 0, kw)
return self.viewSearchRelatedDocumentDialog( return self.viewSearchRelatedDocumentDialog(
method_count, form_id, method_count, form_id,
REQUEST=REQUEST, sub_index=sub_index, **kw) REQUEST=REQUEST, sub_index=sub_index, **kw)
setattr(self.__class__, name, setattr(self.__class__, name,
viewSearchRelatedDocumentDialogWrapper) viewSearchRelatedDocumentDialogWrapper)
klass = aq_base(self).__class__ klass = aq_base(self).__class__
...@@ -1192,22 +1230,22 @@ class TreeListLine: ...@@ -1192,22 +1230,22 @@ class TreeListLine:
self.exception_uid_list=exception_uid_list self.exception_uid_list=exception_uid_list
def getObject(self): def getObject(self):
return self.object return self.object
def getIsPureSummary(self): def getIsPureSummary(self):
return self.is_pure_summary return self.is_pure_summary
def getDepth(self): def getDepth(self):
return self.depth return self.depth
def getIsOpen(self): def getIsOpen(self):
return self.is_open return self.is_open
def getSelectDomainDict(self): def getSelectDomainDict(self):
return self.select_domain_dict return self.select_domain_dict
def getExceptionUidList(self): def getExceptionUidList(self):
return self.exception_uid_list return self.exception_uid_list
def makeTreeList(here, form, root_dict, report_path, base_category, depth, unfolded_list, form_id, selection_name, report_depth, is_report_opened=1, sort_on = (('id', 'ASC'),)): def makeTreeList(here, form, root_dict, report_path, base_category, depth, unfolded_list, form_id, selection_name, report_depth, is_report_opened=1, sort_on = (('id', 'ASC'),)):
""" """
...@@ -1274,7 +1312,7 @@ def makeTreeList(here, form, root_dict, report_path, base_category, depth, unfol ...@@ -1274,7 +1312,7 @@ def makeTreeList(here, form, root_dict, report_path, base_category, depth, unfol
for sub_zo in o.searchFolder(sort_on=sort_on): for sub_zo in o.searchFolder(sort_on=sort_on):
sub_o = sub_zo.getObject() sub_o = sub_zo.getObject()
if sub_o is not None and hasattr(aq_base(root), 'objectValues'): if sub_o is not None and hasattr(aq_base(root), 'objectValues'):
exception_uid_list.append(sub_o.getUid()) exception_uid_list.append(sub_o.getUid())
tree_list += [TreeListLine(o, 1, depth, 1, selection_domain, exception_uid_list)] # Summary (open) tree_list += [TreeListLine(o, 1, depth, 1, selection_domain, exception_uid_list)] # Summary (open)
if is_report_opened : if is_report_opened :
tree_list += [TreeListLine(o, 0, depth, 0, selection_domain, exception_uid_list)] # List (contents, closed, must be strict selection) tree_list += [TreeListLine(o, 0, depth, 0, selection_domain, exception_uid_list)] # List (contents, closed, must be strict selection)
...@@ -1295,12 +1333,12 @@ def makeTreeList(here, form, root_dict, report_path, base_category, depth, unfol ...@@ -1295,12 +1333,12 @@ def makeTreeList(here, form, root_dict, report_path, base_category, depth, unfol
tree_list += [TreeListLine(o, 1, depth, 1, selection_domain, None)] # Summary (open) tree_list += [TreeListLine(o, 1, depth, 1, selection_domain, None)] # Summary (open)
if is_report_opened : if is_report_opened :
tree_list += [TreeListLine(o, 0, depth, 0, selection_domain, None)] # List (contents, closed, must be strict selection) tree_list += [TreeListLine(o, 0, depth, 0, selection_domain, None)] # List (contents, closed, must be strict selection)
tree_list += makeTreeList(here, form, new_root_dict, report_path, base_category, depth + 1, tree_list += makeTreeList(here, form, new_root_dict, report_path, base_category, depth + 1,
unfolded_list, form_id, selection_name, report_depth, unfolded_list, form_id, selection_name, report_depth,
is_report_opened=is_report_opened, sort_on=sort_on) is_report_opened=is_report_opened, sort_on=sort_on)
else: else:
tree_list += [TreeListLine(o, 1, depth, 0, selection_domain, None)] # Summary (closed) tree_list += [TreeListLine(o, 1, depth, 0, selection_domain, None)] # Summary (closed)
return tree_list return tree_list
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