From c984cb3c5d05fef1ce3bcf384ddc3454244a6f86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com> Date: Tue, 6 Jun 2006 14:19:56 +0000 Subject: [PATCH] add a docstring for updateRelatedContent, wrap some long lines and remove useless LOGs git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@7618 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/CMFCategory/CategoryTool.py | 57 ++++++++++++++++++----------- product/ERP5/Tool/CategoryTool.py | 24 +++++++----- 2 files changed, 51 insertions(+), 30 deletions(-) diff --git a/product/CMFCategory/CategoryTool.py b/product/CMFCategory/CategoryTool.py index 0ede2f98c9..a0dad1810a 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 f1ff6e8faa..deb92445c3 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 ) -- 2.30.9