Commit 01338ab2 authored by Romain Courteaud's avatar Romain Courteaud

Change code layout.

_edit does not call reindexObject anymore if no property is changed.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@3702 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent b9def522
...@@ -74,29 +74,30 @@ from zLOG import LOG, INFO, ERROR, WARNING ...@@ -74,29 +74,30 @@ from zLOG import LOG, INFO, ERROR, WARNING
class WorkflowMethod(Method): class WorkflowMethod(Method):
def __init__(self, method, id=None, reindex=1): def __init__(self, method, id=None, reindex=1):
self._m = method self._m = method
if id is None: if id is None:
id = method.__name__ id = method.__name__
self._id = id self._id = id
def __call__(self, instance, *args, **kw):
def __call__(self, instance, *args, **kw):
""" Invoke the wrapped method, and deal with the results. """
""" Invoke the wrapped method, and deal with the results.
wf = getToolByName(instance, 'portal_workflow', None) """
if wf is None or not hasattr(wf, 'wrapWorkflowMethod'): wf = getToolByName(instance, 'portal_workflow', None)
# No workflow tool found. if wf is None or not hasattr(wf, 'wrapWorkflowMethod'):
try: # No workflow tool found.
res = apply(self._m, (instance,) + args, kw) try:
except ObjectDeleted, ex: res = apply(self._m, (instance,) + args, kw)
res = ex.getResult() except ObjectDeleted, ex:
else: res = ex.getResult()
if hasattr(aq_base(instance), 'reindexObject'): else:
instance.reindexObject() if hasattr(aq_base(instance), 'reindexObject'):
else: instance.reindexObject()
res = wf.wrapWorkflowMethod(instance, self._id, self.__dict__['_m'], else:
(instance,) + args, kw) res = wf.wrapWorkflowMethod(instance, self._id, self.__dict__['_m'],
return res (instance,) + args, kw)
return res
def _aq_reset(): def _aq_reset():
...@@ -877,7 +878,7 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ): ...@@ -877,7 +878,7 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
# 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, **kw): def _edit(self, REQUEST=None, force_update=0, reindex_object=0, **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
...@@ -912,23 +913,36 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ): ...@@ -912,23 +913,36 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
else: else:
old_value = None old_value = None
if old_value != kw[key] or force_update: if old_value != kw[key] or force_update:
self._v_modified_property_dict[key] = old_value # We keep in a thread var the previous values - this can be useful for interaction workflow to implement lookups # We keep in a thread var the previous values
# this can be useful for interaction workflow to implement lookups
self._v_modified_property_dict[key] = old_value
self._setProperty(key, kw[key]) self._setProperty(key, kw[key])
elif self.id != kw['id']: elif self.id != kw['id']:
self.recursiveFlushActivity(invoke=1) # Do not rename until everything flushed # XXX Do not rename until everything flushed
self.recursiveFlushActivity(invoke=1)
previous_relative_url = self.getRelativeUrl() previous_relative_url = self.getRelativeUrl()
self.aq_parent.manage_renameObjects([self.id], [kw['id']]) self.aq_parent.manage_renameObjects([self.id], [kw['id']])
new_relative_url = self.getRelativeUrl() new_relative_url = self.getRelativeUrl()
id_changed = 1 id_changed = 1
if reindex_object: self.reindexObject() if reindex_object:
# We do not want to reindex the object if nothing is changed
if (self._v_modified_property_dict != {}) or\
id_changed:
self.reindexObject()
if id_changed: if id_changed:
if reindex_object: self.flushActivity(invoke=1) # Required if we wish that news ids appear instantly if reindex_object:
# Required if we wish that news ids appear instantly
self.flushActivity(invoke=1)
#if self.isIndexable: #if self.isIndexable:
# self.moveObject() # Required if we wish that news ids appear instantly # Required if we wish that news ids appear instantly
# self.moveObject()
#if hasattr(aq_base(self), 'recursiveMoveObject'): #if hasattr(aq_base(self), 'recursiveMoveObject'):
# self.recursiveMoveObject() # Required to make sure path of subobjects is updated # Required to make sure path of subobjects is updated
self.activate().updateRelatedContent(previous_relative_url, new_relative_url) # self.recursiveMoveObject()
#self.activate().recursiveImmediateReindexObject() # Required to update path / relative_url of subobjects self.activate().updateRelatedContent(previous_relative_url,
new_relative_url)
# Required to update path / relative_url of subobjects
#self.activate().recursiveImmediateReindexObject()
security.declareProtected( Permissions.ModifyPortalContent, 'setId' ) security.declareProtected( Permissions.ModifyPortalContent, 'setId' )
def setId(self, id, reindex = 1): def setId(self, id, reindex = 1):
...@@ -949,11 +963,16 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ): ...@@ -949,11 +963,16 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
""" """
self._getCategoryTool().updateRelatedContent(self, previous_category_url, new_category_url) self._getCategoryTool().updateRelatedContent(self, previous_category_url, new_category_url)
security.declareProtected( Permissions.ModifyPortalContent, 'edit' ) security.declareProtected(Permissions.ModifyPortalContent, 'edit')
def edit(self, REQUEST=None, force_update = 0, reindex_object=1, **kw): def edit(self, REQUEST=None, force_update=0, reindex_object=1, **kw):
return self._edit(REQUEST=REQUEST, force_update=force_update, reindex_object=reindex_object, **kw) """
Generic edit Method for all ERP5 object
"""
return self._edit(REQUEST=REQUEST, force_update=force_update,
reindex_object=reindex_object, **kw)
edit = WorkflowMethod( edit ) # XXX Is this useful ? (Romain)
edit = WorkflowMethod(edit)
# Accessing object property Ids # Accessing object property Ids
security.declareProtected( Permissions.View, 'getPropertyIdList' ) security.declareProtected( Permissions.View, 'getPropertyIdList' )
......
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