Commit 85850704 authored by Vincent Pelletier's avatar Vincent Pelletier

_redirectToOriginalForm

 Deprecate query_string parameter.
  New correct way is to provide the parameter in their "native" format, in the request.
  This allows more flexible filtering of parameters.
 Grab dialog_id if present, to fix relation string field listbox redirecting to object view when changing page.
firstPage
lastPage
nextPage
previousPage
setPage
 Make list_selection_name a mandatory parameter, because walling those functions without it has no meaning and must never happen.
 Save one selection edition by changing the page using html parameter to the listbox (so it's only edited by the listbox rendering code, not before the redirection).



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@11183 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 6b3c641d
...@@ -87,28 +87,39 @@ class SelectionTool( UniqueObject, SimpleItem ): ...@@ -87,28 +87,39 @@ class SelectionTool( UniqueObject, SimpleItem ):
, 'manage_view_selections' ) , 'manage_view_selections' )
manage_view_selections = DTMLFile( 'SelectionTool_manageViewSelections', _dtmldir ) manage_view_selections = DTMLFile( 'SelectionTool_manageViewSelections', _dtmldir )
_query_string_reset_regexp = re.compile('\\breset(:int|)?=') def _redirectToOriginalForm(self, REQUEST=None, form_id=None, dialog_id=None,
_query_string_report_depth_regexp = re.compile('\\breport_depth(:int|)?=') query_string=None,
def _redirectToOriginalForm(self, REQUEST=None, form_id=None, query_string=None,
no_reset=False, no_report_depth=False): no_reset=False, no_report_depth=False):
"""Redirect to the original form, using the information given as parameters. """Redirect to the original form or dialog, using the information given
as parameters.
DEPRECATED parameters :
query_string is used to transmit parameters from caller to callee.
If no_reset is True, replace reset parameters with noreset. If no_reset is True, replace reset parameters with noreset.
If no_report_depth is True, replace report_depth parameters with noreport_depth. If no_report_depth is True, replace report_depth parameters with
noreport_depth.
""" """
if REQUEST is None: if REQUEST is None:
return return
context = self.aq_parent parameter_list = REQUEST.form.copy()
form_id = form_id or REQUEST.get('form_id', 'view') if no_reset and parameter_list.has_key('reset'):
url = context.absolute_url() + '/' + form_id parameter_list['noreset'] = parameter_list['reset'] # Kept for compatibility - might no be used anymore
del parameter_list['reset']
if no_report_depth and parameter_list.has_key('report_depth'):
parameter_list['noreport_depth'] = parameter_list['report_depth'] # Kept for compatibility - might no be used anymore
del parameter_list['report_depth']
rendered_parameter_list = make_query(dict([(k, v) for k, v in REQUEST.form.iteritems() if v is not None]))
if query_string is not None: if query_string is not None:
if no_reset: LOG('SelectionTool', 0, 'DEPRECATED: _redirectToOriginalForm got called with a query_string. The variables must be passed in REQUEST.form.')
query_string = self._query_string_reset_regexp.sub('noreset\\1=',
query_string) context = self.aq_parent
if no_report_depth: form_id = dialog_id or REQUEST.get('dialog_id', None) or form_id or REQUEST.get('form_id', 'view')
query_string = self._query_string_report_depth_regexp.sub('noreport_depth\\1=', url = context.absolute_url() + '/' + form_id
query_string) if len(rendered_parameter_list) > 0:
url = url + '?' + query_string url = '%s?%s' % (url, rendered_parameter_list)
return REQUEST.RESPONSE.redirect(url) return REQUEST.RESPONSE.redirect(url)
security.declareProtected(ERP5Permissions.View, 'getSelectionNames') security.declareProtected(ERP5Permissions.View, 'getSelectionNames')
...@@ -524,101 +535,77 @@ class SelectionTool( UniqueObject, SimpleItem ): ...@@ -524,101 +535,77 @@ class SelectionTool( UniqueObject, SimpleItem ):
# ListBox related methods # ListBox related methods
security.declareProtected(ERP5Permissions.View, 'firstPage') security.declareProtected(ERP5Permissions.View, 'firstPage')
def firstPage(self, 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
""" """
if uids is None: uids = [] if uids is None: uids = []
request = REQUEST selection = self.getSelectionFor(list_selection_name, REQUEST)
#form_id = request.form_id REQUEST.form['list_start'] = 0
selection_name = request.list_selection_name self.uncheckAll(list_selection_name, listbox_uid)
selection = self.getSelectionFor(selection_name, REQUEST) return self.checkAll(list_selection_name, uids, REQUEST=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') security.declareProtected(ERP5Permissions.View, 'lastPage')
def lastPage(self, 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
""" """
if uids is None: uids = [] if uids is None: uids = []
request = REQUEST selection = self.getSelectionFor(list_selection_name, REQUEST)
#form_id = request.form_id
selection_name = request.list_selection_name
selection = self.getSelectionFor(selection_name, REQUEST)
params = selection.getParams() params = selection.getParams()
# XXX This will not work if the number of lines shown in the listbox is greater # 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 # 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 # 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 = REQUEST.form.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 = params.get('list_lines', 1)
last_page_start = int(total_lines) - (int(total_lines) % int(lines_per_page)) last_page_start = int(total_lines) - (int(total_lines) % int(lines_per_page))
params['list_start'] = last_page_start REQUEST.form['list_start'] = last_page_start
selection.edit(params=params) self.uncheckAll(list_selection_name, listbox_uid)
self.uncheckAll(selection_name, listbox_uid) return self.checkAll(list_selection_name, uids, REQUEST=REQUEST)
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, list_selection_name, listbox_uid, uids=None, REQUEST=None):
""" """
Access the next page of a list Access the next page of a list
""" """
if uids is None: uids = [] if uids is None: uids = []
request = REQUEST selection = self.getSelectionFor(list_selection_name, REQUEST)
#form_id = request.form_id
selection_name = request.list_selection_name
selection = self.getSelectionFor(selection_name, REQUEST)
params = selection.getParams() params = selection.getParams()
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) REQUEST.form['list_start'] = int(start) + int(lines)
selection.edit(params=params) self.uncheckAll(list_selection_name, listbox_uid)
self.uncheckAll(selection_name, listbox_uid) return self.checkAll(list_selection_name, uids, REQUEST=REQUEST)
return self.checkAll(selection_name, uids, REQUEST=REQUEST)
security.declareProtected(ERP5Permissions.View, 'previousPage') security.declareProtected(ERP5Permissions.View, 'previousPage')
def previousPage(self, listbox_uid, uids=None, REQUEST=None): def previousPage(self, list_selection_name, listbox_uid, uids=None, REQUEST=None):
""" """
Access the previous page of a list Access the previous page of a list
""" """
if uids is None: uids = [] if uids is None: uids = []
request = REQUEST selection = self.getSelectionFor(list_selection_name, REQUEST)
#form_id = request.form_id
selection_name = request.list_selection_name
selection = self.getSelectionFor(selection_name, REQUEST)
params = selection.getParams() params = selection.getParams()
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) REQUEST.form['list_start'] = max(int(start) - int(lines), 0)
selection.edit(params=selection.params) self.uncheckAll(list_selection_name, listbox_uid)
self.uncheckAll(selection_name, listbox_uid) return self.checkAll(list_selection_name, uids, REQUEST=REQUEST)
return self.checkAll(selection_name, uids, REQUEST=REQUEST)
security.declareProtected(ERP5Permissions.View, 'setPage') security.declareProtected(ERP5Permissions.View, 'setPage')
def setPage(self, listbox_uid, query_string=None, uids=None, REQUEST=None): def setPage(self, list_selection_name, listbox_uid, query_string=None, uids=None, REQUEST=None):
""" """
Access the previous page of a list Access the previous page of a list
""" """
if uids is None: uids = [] if uids is None: uids = []
request = REQUEST selection = self.getSelectionFor(list_selection_name, REQUEST)
#form_id = request.form_id params = selection.getParams()
selection_name = request.list_selection_name params['list_start'] = REQUEST.form.get('list_start', 0)
selection = self.getSelectionFor(selection_name, REQUEST=REQUEST) selection.edit(params=params)
if selection is not None: self.uncheckAll(list_selection_name, listbox_uid)
params = selection.getParams() return self.checkAll(list_selection_name, uids, REQUEST=REQUEST, query_string=query_string)
lines = params.get('list_lines',0)
start = request.form.get('list_start',0)
params['list_start'] = start
selection.edit(params= selection.params)
self.uncheckAll(selection_name, listbox_uid)
return self.checkAll(selection_name, uids, REQUEST=REQUEST, query_string=query_string)
# PlanningBox related methods # PlanningBox related methods
......
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