From 1f244d6eb95ddc18076303e44dda9843ca72a964 Mon Sep 17 00:00:00 2001 From: Romain Courteaud <romain@nexedi.com> Date: Tue, 12 Dec 2006 13:59:00 +0000 Subject: [PATCH] When doing copy/paste, check the relation of the subobjects, and update them if necessary. A volatile attribute is used because of the limitation of CopySupport API. git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@11691 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/ERP5Type/CopySupport.py | 42 +++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/product/ERP5Type/CopySupport.py b/product/ERP5Type/CopySupport.py index 60400702b8..65442e498e 100644 --- a/product/ERP5Type/CopySupport.py +++ b/product/ERP5Type/CopySupport.py @@ -138,7 +138,9 @@ class CopyContainer: # Search for categories that have to be updated in sub objects. self._recursiveSetActivityAfterTag(ob) - self._updateInternalRelatedContent(local_self=ob, path=ob.getRelativeUrl().split("/"), new_id=new_id) + self._updateInternalRelatedContent(local_self=ob, + path=ob.getRelativeUrl().split("/"), + new_id=new_id) #ob._v_is_renamed = 1 # Rename the object return OriginalCopyContainer.manage_renameObject(self, id=id, new_id=new_id, REQUEST=REQUEST) @@ -370,17 +372,37 @@ class CopyContainer: self._v_category_url_before_move = self.getRelativeUrl() self._recursiveSetActivityAfterTag(self) + def _setId(self, id): + # Called to set the new id of a copied object. + # XXX It is bad to use volatile attribute, because we may have naming + # conflict later. + # Currently, it is required to use this volatile attribute + # when we do a copy/paste, in order to change the relation in _postCopy. + # Such implementation is due to the limitation of CopySuport API, which prevent + # to pass parameter to manage_afterClone. + self._v_previous_id = self.id + self.id=id + def _postCopy(self, container, op=0): - # Called after the copy is finished to accomodate special cases. - # in our case, we want to notify the category system that our path + # Called after the copy is finished to accomodate special cases. + # The op var is 0 for a copy, 1 for a move. + if op == 1: + # In our case, we want to notify the category system that our path # changed, so that it updates related objects. - if op == 1: - old_url = getattr(self, '_v_category_url_before_move', None) - if old_url is not None: - self.activate(after_method_id='unindexObject').updateRelatedContent( - old_url, - self.getRelativeUrl()) - + old_url = getattr(self, '_v_category_url_before_move', None) + if old_url is not None: + self.activate(after_method_id='unindexObject').updateRelatedContent( + old_url, + self.getRelativeUrl()) + elif op == 0: + # Paste a object. + # Update related subcontent + previous_path = self.getRelativeUrl().split('/') + previous_path[-1] = self._v_previous_id + + self._updateInternalRelatedContent(local_self=self, + path=previous_path, + new_id=self.id) #### Helper methods -- 2.30.9