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,22 +158,24 @@ class Selection(Acquisition.Implicit, Traversable, Persistent): ...@@ -158,22 +158,24 @@ class Selection(Acquisition.Implicit, Traversable, Persistent):
security.declarePrivate('edit') security.declarePrivate('edit')
def edit(self, params=None, **kw): def edit(self, params=None, **kw):
if self.isMemcachedUsed():
setattr(self, MEMCACHED_TOOL_MODIFIED_FLAG_PROPERTY_ID, True) setattr(self, MEMCACHED_TOOL_MODIFIED_FLAG_PROPERTY_ID, True)
if params is not None: if params is not None:
self.params = {}
for key in params.keys():
# We should only keep params which do not start with field_ # We should only keep params which do not start with field_
# in order to make sure we do not collect unwanted params # in order to make sure we do not collect unwanted params
# resulting form the REQUEST generated by an ERP5Form submit # resulting form the REQUEST generated by an ERP5Form submit
if key[0:6] != 'field_': params = dict([item for item in params.iteritems() \
self.params[key] = params[key] if not item[0].startswith('field_')])
if self.params != params:
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')
if getattr(self, k, None) != v:
setattr(self, k, v) setattr(self, k, v)
def _p_independent(self) : def _p_independent(self) :
......
...@@ -200,6 +200,7 @@ class SelectionTool( BaseTool, UniqueObject, SimpleItem ): ...@@ -200,6 +200,7 @@ 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)
if self.getSelectionFor(selection_name) != selection_object:
self._setSelectionToContainer(selection_name, selection_object) self._setSelectionToContainer(selection_name, selection_object)
security.declareProtected(ERP5Permissions.View, 'getSelectionParamsFor') security.declareProtected(ERP5Permissions.View, 'getSelectionParamsFor')
...@@ -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