Commit 9b022399 authored by Julien Muchembled's avatar Julien Muchembled

CategoryTool: optimize getCategoryList and getAcquiredCategoryList

parent dd5ffa73
...@@ -1152,21 +1152,17 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -1152,21 +1152,17 @@ class CategoryTool( UniqueObject, Folder, Base ):
security.declareProtected( Permissions.AccessContentsInformation, 'getCategoryList' ) security.declareProtected( Permissions.AccessContentsInformation, 'getCategoryList' )
def getCategoryList(self, context): def getCategoryList(self, context):
if getattr(aq_base(context), 'categories', _marker) is not _marker: result = getattr(aq_base(context), 'categories', None)
if isinstance(context.categories, tuple): if result is not None:
result = list(context.categories) result = list(result)
elif isinstance(context.categories, list):
result = context.categories
else:
result = []
elif isinstance(context, dict): elif isinstance(context, dict):
result = list(context.get('categories', [])) return list(context.get('categories', ()))
else: else:
result = [] result = []
if getattr(context, 'isCategory', 0): if getattr(context, 'isCategory', 0):
category_url = context.getRelativeUrl() category_url = context.getRelativeUrl()
if category_url not in result: if category_url not in result:
result.append(context.getRelativeUrl()) # Pure category is member of itself result.append(category_url) # Pure category is member of itself
return result return result
_getCategoryList = getCategoryList _getCategoryList = getCategoryList
...@@ -1184,12 +1180,10 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -1184,12 +1180,10 @@ class CategoryTool( UniqueObject, Folder, Base ):
def getAcquiredCategoryList(self, context): 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 for c in self._getCategoryList(context):
non_acquired = self._getCategoryList(context)
for c in non_acquired:
# Make sure all local categories are considered # Make sure all local categories are considered
if c not in result: if c not in result:
append(c) result.append(c)
return result return result
# Catalog related methods # Catalog related methods
......
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