Commit da187a63 authored by Alexandre Boeglin's avatar Alexandre Boeglin

* add edit_order parameter and logic to _edit() (see changelog of r19605)

* _v_accessor_created_object is no longer useful


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@19606 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 7cc2926b
...@@ -161,7 +161,6 @@ class Setter(Method): ...@@ -161,7 +161,6 @@ class Setter(Method):
if o is None: if o is None:
o = instance.newContent(id=self._storage_id, o = instance.newContent(id=self._storage_id,
portal_type=self._portal_type[0]) portal_type=self._portal_type[0])
instance._v_accessor_created_object = 1
if self._reindex: if self._reindex:
warnings.warn("The reindexing accessors are deprecated.\n" warnings.warn("The reindexing accessors are deprecated.\n"
"Please use Alias.Reindex instead.", "Please use Alias.Reindex instead.",
......
...@@ -227,7 +227,6 @@ class Setter(Method): ...@@ -227,7 +227,6 @@ class Setter(Method):
assertAttributePortalType(instance, available_id, self._portal_type) assertAttributePortalType(instance, available_id, self._portal_type)
o = instance.newContent(id=available_id, o = instance.newContent(id=available_id,
portal_type=self._portal_type[0]) portal_type=self._portal_type[0])
instance._v_accessor_created_object = 1
if self._reindex: if self._reindex:
warnings.warn("The reindexing accessors are deprecated.\n" warnings.warn("The reindexing accessors are deprecated.\n"
"Please use Alias.Reindex instead.", "Please use Alias.Reindex instead.",
......
...@@ -1465,7 +1465,7 @@ class Base( CopyContainer, ...@@ -1465,7 +1465,7 @@ class Base( CopyContainer,
# Object attributes update method # Object attributes update method
security.declarePrivate( '_edit' ) security.declarePrivate( '_edit' )
def _edit(self, REQUEST=None, force_update=0, reindex_object=0, def _edit(self, REQUEST=None, force_update=0, reindex_object=0,
keep_existing=0, activate_kw=None, **kw): keep_existing=0, activate_kw=None, edit_order=[], **kw):
""" """
Generic edit Method for all ERP5 object Generic edit Method for all ERP5 object
The purpose of this method is to update attributed, eventually do The purpose of this method is to update attributed, eventually do
...@@ -1483,46 +1483,34 @@ class Base( CopyContainer, ...@@ -1483,46 +1483,34 @@ class Base( CopyContainer,
""" """
modified_property_dict = self._v_modified_property_dict = {} modified_property_dict = self._v_modified_property_dict = {}
def getModifiedPropertyList(self): key_list = kw.keys()
my_modified_property_list = [] ordered_key_list = [k for k in key_list if k not in edit_order]
for key in kw.keys(): for k in edit_order:
# We only change if the value is different if k in key_list:
# This may be very long... ordered_key_list.append(k)
old_value = None
if not force_update: for key in ordered_key_list:
try: # We only change if the value is different
old_value = self.getProperty(key, evaluate=0) # This may be very long...
except TypeError: old_value = None
old_value = self.getProperty(key) if not force_update:
try:
if old_value != kw[key] or force_update: old_value = self.getProperty(key, evaluate=0)
# We keep in a thread var the previous values except TypeError:
# this can be useful for interaction workflow to implement lookups old_value = self.getProperty(key)
# XXX If iteraction workflow script is triggered by edit and calls
# edit itself, this is useless as the dict will be overwritten if old_value != kw[key] or force_update:
# If the keep_existing flag is set to 1, we do not update properties which are defined # We keep in a thread var the previous values
if not keep_existing or not self.hasProperty(key): # this can be useful for interaction workflow to implement lookups
modified_property_dict[key] = old_value # XXX If iteraction workflow script is triggered by edit and calls
my_modified_property_list.append(key) # edit itself, this is useless as the dict will be overwritten
return my_modified_property_list # If the keep_existing flag is set to 1, we do not update properties which are defined
if not keep_existing or not self.hasProperty(key):
my_modified_property_list = getModifiedPropertyList(self) modified_property_dict[key] = old_value
if key != 'id':
# When we get notified by an accessor that it created an object, recheck self._setProperty(key, kw[key])
# all properties else:
while 1: self.setId(kw['id'], reindex=reindex_object)
self._v_accessor_created_object = 0
for key in my_modified_property_list:
if key != 'id':
self._setProperty(key, kw[key])
else:
self.setId(kw['id'], reindex=reindex_object)
if self._v_accessor_created_object == 1:
# refresh list of modified properties, and restart the process
my_modified_property_list = getModifiedPropertyList(self)
break
else:
break
if reindex_object: if reindex_object:
# We do not want to reindex the object if nothing is changed # We do not want to reindex the object if nothing is changed
......
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