[Erp5-report] r7618 - in /erp5/trunk/products: CMFCategory/ ERP5/Tool/
nobody at svn.erp5.org
nobody at svn.erp5.org
Tue Jun 6 16:20:00 CEST 2006
Author: jerome
Date: Tue Jun 6 16:19:56 2006
New Revision: 7618
URL: http://svn.erp5.org?rev=7618&view=rev
Log:
add a docstring for updateRelatedContent, wrap some long lines and
remove useless LOGs
Modified:
erp5/trunk/products/CMFCategory/CategoryTool.py
erp5/trunk/products/ERP5/Tool/CategoryTool.py
Modified: erp5/trunk/products/CMFCategory/CategoryTool.py
URL: http://svn.erp5.org/erp5/trunk/products/CMFCategory/CategoryTool.py?rev=7618&r1=7617&r2=7618&view=diff
==============================================================================
--- erp5/trunk/products/CMFCategory/CategoryTool.py (original)
+++ erp5/trunk/products/CMFCategory/CategoryTool.py Tue Jun 6 16:19:56 2006
@@ -1206,40 +1206,55 @@
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)
- """
- 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()):
+ 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)
+ """
+ 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):
"""
Modified: erp5/trunk/products/ERP5/Tool/CategoryTool.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Tool/CategoryTool.py?rev=7618&r1=7617&r2=7618&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Tool/CategoryTool.py (original)
+++ erp5/trunk/products/ERP5/Tool/CategoryTool.py Tue Jun 6 16:19:56 2006
@@ -121,26 +121,32 @@
security.declareProtected(Permissions.AccessContentsInformation, 'getUids')
getUids = getCategoryParentUidList
- def updateRelatedContent(self, context, previous_category_url, new_category_url):
+ def updateRelatedContent(self, context,
+ previous_category_url, new_category_url):
+ """See CMFCategory.CategoryTool.updateRelatedContent
+
+ This method also update all predicates membership
"""
- TODO: make this method resist to very large updates (ie. long transaction)
- """
- 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 )
More information about the Erp5-report
mailing list