diff --git a/product/CMFCategory/CategoryTool.py b/product/CMFCategory/CategoryTool.py index 0ede2f98c96728527176a951ad4242fff1819d74..a0dad1810a5c1004b4ec2eaecaf8d823623ecd74 100644 --- a/product/CMFCategory/CategoryTool.py +++ b/product/CMFCategory/CategoryTool.py @@ -1206,40 +1206,55 @@ class CategoryTool( UniqueObject, Folder, Base ): previous_category_url,'\g<start>/%s' % new_category_url, new_category) return new_category - def updateRelatedContent(self, context, previous_category_url, new_category_url): - """ - TODO: make this method resist to very large updates (ie. long transaction) + def updateRelatedContent(self, context, + previous_category_url, new_category_url): + """Updates related object when an object have moved. + + o context: the moved object + o previous_category_url: the related url of this object before + the move + o new_category_url: the related url of the object after the move + + TODO: make this method resist to very large updates (ie. long transaction) """ - LOG('CMFCategoryTool, context',0,context) - LOG('CMFCategoryTool, previous_category_url',0,previous_category_url) - LOG('CMFCategoryTool, new_category_url',0,new_category_url) - for brain in self.Base_zSearchRelatedObjectsByCategory(category_uid = context.getUid()): + for brain in self.Base_zSearchRelatedObjectsByCategory( + category_uid = context.getUid()): o = brain.getObject() if o is not None: category_list = [] - LOG('CMFCategoryTool, previous category_list',0,self.getCategoryList(o)) for category in self.getCategoryList(o): - new_category = self.updateRelatedCategory(category,previous_category_url,new_category_url) + new_category = self.updateRelatedCategory(category, + previous_category_url, + new_category_url) category_list += [new_category] self._setCategoryList(o, category_list) - LOG('CMFCategoryTool, new category_list',0,category_list) + if hasattr(aq_base(o), 'notifyAfterUpdateRelatedContent'): - o.notifyAfterUpdateRelatedContent(previous_category_url, new_category_url) + o.notifyAfterUpdateRelatedContent(previous_category_url, + new_category_url) + else: - LOG('WARNING updateRelatedContent',0,'%s does not exist' % brain.path) + LOG('CMFCategory', PROBLEM, + 'updateRelatedContent: %s does not exist' % brain.path) + aq_context = aq_base(context) # Update related recursively if required if hasattr(aq_context, 'listFolderContents'): for o in context.listFolderContents(): - new_o_category_url = o.getRelativeUrl() # Relative Url is based on parent new_category_url - # so we must replace new_category_url with previous_category_url to find - # the previous category_url for a - previous_o_category_url = self.updateRelatedCategory(new_o_category_url,new_category_url,previous_category_url) - #previous_o_category_url = re.sub('(?P<start>.*)/%s$' % - # new_category_url,'\g<start>/%s' % previous_category_url, new_o_category_url) - self.updateRelatedContent(o, previous_o_category_url, new_o_category_url) - - security.declareProtected( Permissions.AccessContentsInformation, 'getRelatedValueList' ) + new_o_category_url = o.getRelativeUrl() + # Relative Url is based on parent new_category_url so we must + # replace new_category_url with previous_category_url to find + # the new category_url for the subobject + previous_o_category_url = self.updateRelatedCategory( + new_o_category_url, + new_category_url, + previous_category_url) + + self.updateRelatedContent(o, previous_o_category_url, + new_o_category_url) + + security.declareProtected( Permissions.AccessContentsInformation, + 'getRelatedValueList' ) def getRelatedValueList(self, context, base_category_list=None, spec=(), filter=None, base=1, **kw): """ diff --git a/product/ERP5/Tool/CategoryTool.py b/product/ERP5/Tool/CategoryTool.py index f1ff6e8faa327b590f5972125b289c24d023c8a1..deb92445c3759b7f10c4b78318995266ed907ed5 100644 --- a/product/ERP5/Tool/CategoryTool.py +++ b/product/ERP5/Tool/CategoryTool.py @@ -121,26 +121,32 @@ class CategoryTool(CopyContainer, CMFCategoryTool, BaseTool): security.declareProtected(Permissions.AccessContentsInformation, 'getUids') getUids = getCategoryParentUidList - def updateRelatedContent(self, context, previous_category_url, new_category_url): - """ - TODO: make this method resist to very large updates (ie. long transaction) + def updateRelatedContent(self, context, + previous_category_url, new_category_url): + """See CMFCategory.CategoryTool.updateRelatedContent + + This method also update all predicates membership """ - CMFCategoryTool.updateRelatedContent(self,context,previous_category_url,new_category_url) + CMFCategoryTool.updateRelatedContent(self, + context,previous_category_url, + new_category_url) # We also need to udpate all predicates membership - domain_tool = getToolByName(context,'portal_domains') - portal_catalog = getToolByName(context,'portal_catalog') + domain_tool = getToolByName(context, 'portal_domains') + portal_catalog = getToolByName(context, 'portal_catalog') kw = {} kw['predicate_category.category_uid'] = context.getUid() object_list = portal_catalog(**kw) for predicate in [x.getObject() for x in object_list]: membership_list = [] for category in predicate.getMembershipCriterionCategoryList(): - new_category = self.updateRelatedCategory(category, previous_category_url, new_category_url) + new_category = self.updateRelatedCategory(category, + previous_category_url, + new_category_url) membership_list.append(new_category) predicate.setMembershipCriterionCategoryList(membership_list) - # We do not need to to things recursively since updateRelatedContent is already - # recursive. + # We do not need to to things recursively since + # updateRelatedContent is already recursive. InitializeClass( CategoryTool )