Commit c984cb3c authored by Jérome Perrin's avatar Jérome Perrin

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
parent cfe86769
......@@ -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):
"""
......
......@@ -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 )
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