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