Commit e33ed26b authored by Yoshinori Okuji's avatar Yoshinori Okuji

Prevent modifying a selection object unnecessarily.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@17355 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent b61493b5
......@@ -888,7 +888,7 @@ class ListBoxRenderer:
def getParamDict(self):
"""Return a dictionary of parameters.
"""
params = self.getSelection().getParams()
params = dict(self.getSelection().getParams())
if self.getListMethodName():
# Update parameters, only if list_method is defined.
# (i.e. do not update parameters in listboxes intended to show a previously defined selection.
......@@ -980,6 +980,8 @@ class ListBoxRenderer:
# objects in the current ListBox configuration.
if 'select_expression' in params:
del params['select_expression']
self.getSelection().edit(params=params)
return params
getParamDict = lazyMethod(getParamDict)
......
......@@ -97,7 +97,7 @@ class Selection(Acquisition.Implicit, Traversable, Persistent):
"""
method_path=None
params={}
params=None
sort_on=()
default_sort_on=()
uids=()
......@@ -158,23 +158,25 @@ class Selection(Acquisition.Implicit, Traversable, Persistent):
security.declarePrivate('edit')
def edit(self, params=None, **kw):
setattr(self, MEMCACHED_TOOL_MODIFIED_FLAG_PROPERTY_ID, True)
if self.isMemcachedUsed():
setattr(self, MEMCACHED_TOOL_MODIFIED_FLAG_PROPERTY_ID, True)
if params is not None:
self.params = {}
for key in params.keys():
# We should only keep params which do not start with field_
# in order to make sure we do not collect unwanted params
# resulting form the REQUEST generated by an ERP5Form submit
if key[0:6] != 'field_':
self.params[key] = params[key]
# We should only keep params which do not start with field_
# in order to make sure we do not collect unwanted params
# resulting form the REQUEST generated by an ERP5Form submit
params = dict([item for item in params.iteritems() \
if not item[0].startswith('field_')])
if self.params != params:
self.params = params
if kw is not None:
for k,v in kw.items():
for k,v in kw.iteritems():
if k in ('domain', 'report', 'domain_path', 'report_path', 'domain_list', 'report_list') or v is not None:
# XXX Because method_path is an URI, it must be in ASCII.
# Shouldn't Zope automatically does this conversion? -yo
if k == 'method_path' and type(v) is type(u'a'):
if k == 'method_path' and isinstance(v, unicode):
v = v.encode('ascii')
setattr(self, k, v)
if getattr(self, k, None) != v:
setattr(self, k, v)
def _p_independent(self) :
return 1
......
......@@ -200,7 +200,8 @@ class SelectionTool( BaseTool, UniqueObject, SimpleItem ):
# Set the name so that this selection itself can get its own name.
selection_object.edit(name = selection_name)
self._setSelectionToContainer(selection_name, selection_object)
if self.getSelectionFor(selection_name) != selection_object:
self._setSelectionToContainer(selection_name, selection_object)
security.declareProtected(ERP5Permissions.View, 'getSelectionParamsFor')
def getSelectionParamsFor(self, selection_name, params=None, REQUEST=None):
......@@ -227,7 +228,7 @@ class SelectionTool( BaseTool, UniqueObject, SimpleItem ):
Sets the selection params for a given selection_name
"""
selection_object = self.getSelectionFor(selection_name, REQUEST)
if selection_object:
if selection_object is not None:
selection_object.edit(params=params)
else:
selection_object = Selection(params=params)
......
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