Commit 20a82576 authored by Julien Muchembled's avatar Julien Muchembled

CategoryTool: remove ancient _cleanupCategories migration method

parent 538dd366
...@@ -627,8 +627,6 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -627,8 +627,6 @@ class CategoryTool( UniqueObject, Folder, Base ):
portal_type = (portal_type,) portal_type = (portal_type,)
spec = portal_type spec = portal_type
self._cleanupCategories(context)
if isinstance(category_list, str): if isinstance(category_list, str):
category_list = (category_list, ) category_list = (category_list, )
elif category_list is None: elif category_list is None:
...@@ -705,7 +703,6 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -705,7 +703,6 @@ class CategoryTool( UniqueObject, Folder, Base ):
to filter the object on to filter the object on
""" """
self._cleanupCategories(context)
if isinstance(default_category, (tuple, list)): if isinstance(default_category, (tuple, list)):
default_category = default_category[0] default_category = default_category[0]
category_list = self.getCategoryMembershipList(context, base_category, category_list = self.getCategoryMembershipList(context, base_category,
...@@ -1148,18 +1145,13 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -1148,18 +1145,13 @@ class CategoryTool( UniqueObject, Folder, Base ):
""" """
if getattr(aq_base(context), 'isCategory', 0): if getattr(aq_base(context), 'isCategory', 0):
return context.isAcquiredMemberOf(category) return context.isAcquiredMemberOf(category)
for c in self._getAcquiredCategoryList(context): for c in self.getAcquiredCategoryList(context):
if c.find(category) >= 0: if c.find(category) >= 0:
return 1 return 1
return 0 return 0
security.declareProtected( Permissions.AccessContentsInformation, 'getCategoryList' ) security.declareProtected( Permissions.AccessContentsInformation, 'getCategoryList' )
def getCategoryList(self, context): def getCategoryList(self, context):
self._cleanupCategories(context)
return self._getCategoryList(context)
security.declareProtected( Permissions.AccessContentsInformation, '_getCategoryList' )
def _getCategoryList(self, context):
if getattr(aq_base(context), 'categories', _marker) is not _marker: if getattr(aq_base(context), 'categories', _marker) is not _marker:
if isinstance(context.categories, tuple): if isinstance(context.categories, tuple):
result = list(context.categories) result = list(context.categories)
...@@ -1177,6 +1169,8 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -1177,6 +1169,8 @@ class CategoryTool( UniqueObject, Folder, Base ):
result.append(context.getRelativeUrl()) # Pure category is member of itself result.append(context.getRelativeUrl()) # Pure category is member of itself
return result return result
_getCategoryList = getCategoryList
security.declareProtected( Permissions.ModifyPortalContent, 'setCategoryList' ) security.declareProtected( Permissions.ModifyPortalContent, 'setCategoryList' )
def setCategoryList(self, context, value): def setCategoryList(self, context, value):
self._setCategoryList(context, value) self._setCategoryList(context, value)
...@@ -1188,14 +1182,6 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -1188,14 +1182,6 @@ class CategoryTool( UniqueObject, Folder, Base ):
security.declareProtected( Permissions.AccessContentsInformation, 'getAcquiredCategoryList' ) security.declareProtected( Permissions.AccessContentsInformation, 'getAcquiredCategoryList' )
def getAcquiredCategoryList(self, context): def getAcquiredCategoryList(self, context):
"""
Returns the list of acquired categories
"""
self._cleanupCategories(context)
return self._getAcquiredCategoryList(context)
security.declareProtected( Permissions.AccessContentsInformation, '_getAcquiredCategoryList' )
def _getAcquiredCategoryList(self, context):
result = self.getAcquiredCategoryMembershipList(context, result = self.getAcquiredCategoryMembershipList(context,
base_category = self.getBaseCategoryList(context=context)) base_category = self.getBaseCategoryList(context=context))
append = result.append append = result.append
...@@ -1208,21 +1194,6 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -1208,21 +1194,6 @@ class CategoryTool( UniqueObject, Folder, Base ):
append(context.getRelativeUrl()) # Pure category is member of itself append(context.getRelativeUrl()) # Pure category is member of itself
return result return result
security.declareProtected( Permissions.ModifyPortalContent, '_cleanupCategories' )
def _cleanupCategories(self, context):
# Make sure _cleanupCategories does not modify objects each time it is called
# or we get many conflicts
requires_update = 0
categories = []
append = categories.append
if getattr(context, 'categories', _marker) is not _marker:
for cat in self._getCategoryList(context):
if isinstance(cat, str):
append(cat)
else:
requires_update = 1
if requires_update: self.setCategoryList(context, tuple(categories))
# Catalog related methods # Catalog related methods
def updateRelatedCategory(self, category, previous_category_url, new_category_url): def updateRelatedCategory(self, category, previous_category_url, new_category_url):
new_category = re.sub('^%s$' % new_category = re.sub('^%s$' %
......
...@@ -862,20 +862,19 @@ class TestResource(ERP5TypeTestCase): ...@@ -862,20 +862,19 @@ class TestResource(ERP5TypeTestCase):
self.tic() self.tic()
# Test the cases # Test the cases
for product, variation, node, base_price in test_case_list: for product, variation, node, base_price in test_case_list:
categories = []
if node is not None: if node is not None:
self.logMessage("Check product %s with destination section %s" % \ self.logMessage("Check product %s with destination section %s" % \
(product.getTitle(), node.getTitle()), (product.getTitle(), node.getTitle()),
tab=1) tab=1)
self.assertEquals(base_price, categories.append('destination_section/' + node.getRelativeUrl())
product.getPrice(
categories=['destination_section/%s' % node.getRelativeUrl(),
variation]))
else: else:
self.logMessage("Check product %s without destination section" % \ self.logMessage("Check product %s without destination section" % \
product.getTitle(), product.getTitle(),
tab=1) tab=1)
self.assertEquals(base_price, if variation:
product.getPrice(categories=[variation])) categories.append(variation)
self.assertEqual(base_price, product.getPrice(categories=categories))
# The following test tests Movement.getPrice, which is based on the movement # The following test tests Movement.getPrice, which is based on the movement
......
...@@ -2175,9 +2175,6 @@ class Base( CopyContainer, ...@@ -2175,9 +2175,6 @@ class Base( CopyContainer,
""" """
return self._getCategoryTool().getAcquiredCategoryList(self) return self._getCategoryTool().getAcquiredCategoryList(self)
def _getAcquiredCategoryList(self):
return self._getCategoryTool()._getAcquiredCategoryList(self)
security.declareProtected( Permissions.ModifyPortalContent, 'setCategoryList' ) security.declareProtected( Permissions.ModifyPortalContent, 'setCategoryList' )
def setCategoryList(self, path_list): def setCategoryList(self, path_list):
self.portal_categories.setCategoryList(self, path_list) self.portal_categories.setCategoryList(self, path_list)
......
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