Commit 257306cd authored by Julien Muchembled's avatar Julien Muchembled

CategoryTool: clean up getCategoryParentUidList

parent 9eee056a
...@@ -308,38 +308,34 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -308,38 +308,34 @@ class CategoryTool( UniqueObject, Folder, Base ):
such as site/group/a/b/c/b1/c1 where b and b1 are both children such as site/group/a/b/c/b1/c1 where b and b1 are both children
categories of a. categories of a.
relative_url -- a single relative url of a list of relative_url -- a single relative url or a list of relative urls
relative urls
strict -- if set to 1, only return uids of parents, not strict -- if set to 1, only return uids of parents, not
relative_url relative_url
""" """
uid_dict = {} uid_set = set()
if isinstance(relative_url, str): if isinstance(relative_url, str):
relative_url = (relative_url,) relative_url = (relative_url,)
for path in relative_url: for path in relative_url:
try: try:
o = self.getCategoryValue(path, base_category=base_category) o = self.getCategoryValue(path, base_category=base_category)
if o is not None: if o is not None:
my_base_category = self.getBaseCategoryId(path) if base_category is None:
bo = self.get(my_base_category, None) my_base_category = self.getBaseCategoryId(path)
if bo is not None: else:
bo_uid = int(bo.getUid()) my_base_category = base_category
uid_dict[(int(o.uid), bo_uid, 1)] = 1 # Strict Membership bo_uid = self[my_base_category].getUid()
if o.meta_type == 'CMF Category' or o.meta_type == 'CMF Base Category': uid_set.add((o.getUid(), bo_uid, 1)) # Strict Membership
if not strict:
while o.portal_type == 'Category':
# This goes up in the category tree # This goes up in the category tree
# XXX we should also go up in some other cases.... # XXX we should also go up in some other cases....
# ie. when some documents act as categories # ie. when some documents act as categories
if not strict: o = o.aq_parent # We want acquisition here without aq_inner
while o.meta_type == 'CMF Category': uid_set.add((o.getUid(), bo_uid, 0)) # Non Strict Membership
o = o.aq_parent # We want acquisition here without aq_inner
uid_dict[(int(o.uid), bo_uid, 0)] = 1 # Non Strict Membership
except (KeyError, AttributeError): except (KeyError, AttributeError):
LOG('WARNING: CategoriesTool',0, 'Unable to find uid for %s' % path) LOG('WARNING: CategoriesTool',0, 'Unable to find uid for %s' % path)
return uid_dict.keys() return list(uid_set) # cast to list for <dtml-in>
security.declareProtected(Permissions.AccessContentsInformation, 'getUids')
getUids = getCategoryParentUidList
security.declareProtected(Permissions.AccessContentsInformation, 'getCategoryChildUidList') security.declareProtected(Permissions.AccessContentsInformation, 'getCategoryChildUidList')
def getCategoryChildUidList(self, relative_url, base_category = None, strict=0): def getCategoryChildUidList(self, relative_url, base_category = None, strict=0):
......
...@@ -84,53 +84,6 @@ class CategoryTool(CopyContainer, CMFCategoryTool, BaseTool): ...@@ -84,53 +84,6 @@ class CategoryTool(CopyContainer, CMFCategoryTool, BaseTool):
def hasContent(self,id): def hasContent(self,id):
return id in self.objectIds() return id in self.objectIds()
security.declareProtected(Permissions.AccessContentsInformation, 'getCategoryParentUidList')
def getCategoryParentUidList(self, relative_url, base_category = None, strict=0):
"""
Returns the uids of all categories provided in categorie. This
method can support relative_url such as site/group/a/b/c which
base category is site yet use categories defined in group.
It is also able to use acquisition to create complex categories
such as site/group/a/b/c/b1/c1 where b and b1 are both children
categories of a.
relative_url -- a single relative url of a list of
relative urls
strict -- if set to 1, only return uids of parents, not
relative_url
"""
uid_dict = {}
if type(relative_url) is type('a'): relative_url = (relative_url,)
for path in relative_url:
try:
o = self.getCategoryValue(path, base_category=base_category)
if o is not None:
if base_category is None:
my_base_category = self.getBaseCategoryId(path)
else:
my_base_category = base_category
bo = getattr(self, my_base_category, None)
if bo is not None:
bo_uid = bo.getUid()
uid_dict[(o.getUid(), bo_uid, 1)] = 1 # Strict membership
if o.meta_type == 'ERP5 Category' or o.meta_type == 'ERP5 Base Category' or \
o.meta_type == 'CMF Category' or o.meta_type == 'CMF Base Category':
# This goes up in the category tree
# XXX we should also go up in some other cases....
# ie. when some documents act as categories
if not strict:
while o.meta_type == 'ERP5 Category' or o.meta_type == 'CMF Category':
o = o.aq_parent # We want acquisition here without aq_inner
uid_dict[(o.getUid(), bo_uid, 0)] = 1 # Non strict
except (TypeError, KeyError):
LOG('WARNING: CategoriesTool',0, 'Unable to find uid for %s' % path)
return uid_dict.keys()
security.declareProtected(Permissions.AccessContentsInformation, 'getUids')
getUids = getCategoryParentUidList
@caching_instance_method(id='portal_categories.getBaseCategoryDict', cache_factory='erp5_content_long', cache_id_generator=lambda m, *a, **k:m) @caching_instance_method(id='portal_categories.getBaseCategoryDict', cache_factory='erp5_content_long', cache_id_generator=lambda m, *a, **k:m)
def getBaseCategoryDict(self): def getBaseCategoryDict(self):
""" """
......
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