Commit 2db0e92f authored by Jérome Perrin's avatar Jérome Perrin

private accessor now returns the list of modified objects, so that...

private accessor now returns the list of modified objects, so that Alias.Reindex can reindex modified objects.



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@18784 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent df34859b
...@@ -169,6 +169,7 @@ class Setter(Method): ...@@ -169,6 +169,7 @@ class Setter(Method):
o.setProperty(self._acquired_property, value, *args, **kw) o.setProperty(self._acquired_property, value, *args, **kw)
else: else:
o._setProperty(self._acquired_property, value, *args, **kw) o._setProperty(self._acquired_property, value, *args, **kw)
return (o, )
DefaultSetter = Setter DefaultSetter = Setter
...@@ -54,8 +54,14 @@ class Reindex(Method): ...@@ -54,8 +54,14 @@ class Reindex(Method):
def __call__(self, instance, *args, **kw): def __call__(self, instance, *args, **kw):
method = getattr(instance, self._accessor_id) method = getattr(instance, self._accessor_id)
method(*args, **kw) modified_object_list = method(*args, **kw)
instance.reindexObject() # private methods can return a list of modified objects that this
# accessor have to reindex
if modified_object_list:
for modified_object in modified_object_list:
modified_object.reindexObject()
else:
instance.reindexObject()
class Dummy(Reindex): class Dummy(Reindex):
""" """
...@@ -79,4 +85,5 @@ class Dummy(Reindex): ...@@ -79,4 +85,5 @@ class Dummy(Reindex):
def __call__(self, instance, *args, **kw): def __call__(self, instance, *args, **kw):
method = getattr(instance, self._accessor_id) method = getattr(instance, self._accessor_id)
method(*args, **kw) method(*args, **kw)
\ No newline at end of file
...@@ -69,6 +69,7 @@ class Setter(Method): ...@@ -69,6 +69,7 @@ class Setter(Method):
def __call__(self, instance, *args, **kw): def __call__(self, instance, *args, **kw):
value = args[0] value = args[0]
modified_object_list = []
if not self._reindex: if not self._reindex:
# Modify the property # Modify the property
if value in self._null: if value in self._null:
...@@ -87,10 +88,13 @@ class Setter(Method): ...@@ -87,10 +88,13 @@ class Setter(Method):
instance._setObject(self._storage_id, o) instance._setObject(self._storage_id, o)
o = getattr(instance, self._storage_id) o = getattr(instance, self._storage_id)
o.manage_upload(file = file_upload) o.manage_upload(file = file_upload)
modified_object_list = [o]
else: else:
LOG('ERP5Type WARNING',0,'%s is not an instance of FileUpload' % str(file_upload)) LOG('ERP5Type WARNING',0,'%s is not an instance of FileUpload' % str(file_upload))
else: else:
setattr(instance, self._storage_id, self._cast(args[0])) setattr(instance, self._storage_id, self._cast(args[0]))
modified_object_list.append(instance)
return modified_object_list
else: else:
# Call the private setter # Call the private setter
warnings.warn("The reindexing accessors are deprecated.\n" warnings.warn("The reindexing accessors are deprecated.\n"
......
...@@ -64,6 +64,7 @@ class ListSetter(Method): ...@@ -64,6 +64,7 @@ class ListSetter(Method):
"Please use Alias.Reindex instead.", "Please use Alias.Reindex instead.",
DeprecationWarning) DeprecationWarning)
instance.reindexObject() instance.reindexObject()
return (instance, )
Setter = ListSetter Setter = ListSetter
...@@ -98,6 +99,7 @@ class DefaultSetter(Method): ...@@ -98,6 +99,7 @@ class DefaultSetter(Method):
"Please use Alias.Reindex instead.", "Please use Alias.Reindex instead.",
DeprecationWarning) DeprecationWarning)
instance.reindexObject() instance.reindexObject()
return (instance, )
class SetSetter(Method): class SetSetter(Method):
""" """
...@@ -142,6 +144,7 @@ class SetSetter(Method): ...@@ -142,6 +144,7 @@ class SetSetter(Method):
"Please use Alias.Reindex instead.", "Please use Alias.Reindex instead.",
DeprecationWarning) DeprecationWarning)
instance.reindexObject() instance.reindexObject()
return (instance, )
class DefaultGetter(Method): class DefaultGetter(Method):
......
...@@ -209,6 +209,7 @@ class Setter(Method): ...@@ -209,6 +209,7 @@ class Setter(Method):
# We return the first available object in the list # We return the first available object in the list
o = None o = None
available_id = None available_id = None
modified_object_list = ()
for k in self._storage_id_list: for k in self._storage_id_list:
o = instance._getOb(k, None) o = instance._getOb(k, None)
if o is None: available_id = k if o is None: available_id = k
...@@ -220,6 +221,7 @@ class Setter(Method): ...@@ -220,6 +221,7 @@ class Setter(Method):
o.setProperty(self._acquired_property, *args, **kw) o.setProperty(self._acquired_property, *args, **kw)
else: else:
o._setProperty(self._acquired_property, *args, **kw) o._setProperty(self._acquired_property, *args, **kw)
modified_object_list = (o, )
if o is None and available_id is not None: if o is None and available_id is not None:
from Products.ERP5Type.Utils import assertAttributePortalType from Products.ERP5Type.Utils import assertAttributePortalType
assertAttributePortalType(instance, available_id, self._portal_type) assertAttributePortalType(instance, available_id, self._portal_type)
...@@ -233,6 +235,8 @@ class Setter(Method): ...@@ -233,6 +235,8 @@ class Setter(Method):
o.setProperty(self._acquired_property, *args, **kw) o.setProperty(self._acquired_property, *args, **kw)
else: else:
o._setProperty(self._acquired_property, *args, **kw) o._setProperty(self._acquired_property, *args, **kw)
modified_object_list = (o, )
return modified_object_list
class ListGetter(Method): class ListGetter(Method):
""" """
......
...@@ -188,6 +188,7 @@ class SetSetter(Method): ...@@ -188,6 +188,7 @@ class SetSetter(Method):
# The list has no default property -> it is empty # The list has no default property -> it is empty
new_list_value = [] new_list_value = []
setattr(instance, self._storage_id, tuple(new_list_value)) setattr(instance, self._storage_id, tuple(new_list_value))
return (instance, )
else: else:
# Call the private setter # Call the private setter
warnings.warn("The reindexing accessors are deprecated.\n" warnings.warn("The reindexing accessors are deprecated.\n"
......
...@@ -61,6 +61,7 @@ class SetSetter(Method): ...@@ -61,6 +61,7 @@ class SetSetter(Method):
"Please use Alias.Reindex instead.", "Please use Alias.Reindex instead.",
DeprecationWarning) DeprecationWarning)
instance.reindexObject() instance.reindexObject()
return (instance, )
psyco.bind(__call__) psyco.bind(__call__)
...@@ -84,6 +85,7 @@ class ListSetter(SetSetter): ...@@ -84,6 +85,7 @@ class ListSetter(SetSetter):
"Please use Alias.Reindex instead.", "Please use Alias.Reindex instead.",
DeprecationWarning) DeprecationWarning)
instance.reindexObject() instance.reindexObject()
return (instance, )
psyco.bind(__call__) psyco.bind(__call__)
...@@ -108,6 +110,7 @@ class DefaultSetter(SetSetter): ...@@ -108,6 +110,7 @@ class DefaultSetter(SetSetter):
"Please use Alias.Reindex instead.", "Please use Alias.Reindex instead.",
DeprecationWarning) DeprecationWarning)
instance.reindexObject() instance.reindexObject()
return (instance, )
psyco.bind(__call__) psyco.bind(__call__)
...@@ -497,6 +500,7 @@ class UidListSetter(UidSetSetter): ...@@ -497,6 +500,7 @@ class UidListSetter(UidSetSetter):
"Please use Alias.Reindex instead.", "Please use Alias.Reindex instead.",
DeprecationWarning) DeprecationWarning)
instance.reindexObject() instance.reindexObject()
return (instance, )
UidSetter = UidListSetter UidSetter = UidListSetter
...@@ -519,6 +523,7 @@ class UidDefaultSetter(UidSetSetter): ...@@ -519,6 +523,7 @@ class UidDefaultSetter(UidSetSetter):
"Please use Alias.Reindex instead.", "Please use Alias.Reindex instead.",
DeprecationWarning) DeprecationWarning)
instance.reindexObject() instance.reindexObject()
return (instance, )
class DefaultIdGetter(Method): class DefaultIdGetter(Method):
""" """
......
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