Commit 2e31abea authored by Jean-Paul Smets's avatar Jean-Paul Smets

New naming


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@184 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent eae6b12d
...@@ -34,7 +34,7 @@ from Acquisition import aq_base, aq_inner, aq_parent ...@@ -34,7 +34,7 @@ from Acquisition import aq_base, aq_inner, aq_parent
from Products.ERP5Type import Permissions from Products.ERP5Type import Permissions
from Products.ERP5Type import PropertySheet from Products.ERP5Type import PropertySheet
from Products.ERP5Type.Document.Folder import Folder from Products.ERP5Type.Document import Folder
from zLOG import LOG from zLOG import LOG
...@@ -185,34 +185,34 @@ class Category(Folder): ...@@ -185,34 +185,34 @@ class Category(Folder):
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getCategoryChildTitleItemList') 'getCategoryChildTitleItemList')
def getCategoryChildTitleItemList(self, recursive=1, base='', start_with_empty_tuple=0): def getCategoryChildTitleItemList(self, recursive=1, base='', display_none_category=0):
""" """
Returns a list of tuples by parsing recursively all categories in a Returns a list of tuples by parsing recursively all categories in a
given list of base categories. Uses getTitle as default method given list of base categories. Uses getTitle as default method
""" """
return self.getCategoryChildItemList(recursive = recursive,base=base, return self.getCategoryChildItemList(recursive = recursive,base=base,
start_with_empty_tuple=start_with_empty_tuple,method_name='getTitle') display_none_category=display_none_category,display_id='getTitle')
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getCategoryChildIdItemList') 'getCategoryChildIdItemList')
def getCategoryChildIdItemList(self, recursive=1, base='', start_with_empty_tuple=0): def getCategoryChildIdItemList(self, recursive=1, base='', display_none_category=0):
""" """
Returns a list of tuples by parsing recursively all categories in a Returns a list of tuples by parsing recursively all categories in a
given list of base categories. Uses getId as default method given list of base categories. Uses getId as default method
""" """
return self.getCategoryChildItemList(recursive = recursive,base=base, return self.getCategoryChildItemList(recursive = recursive,base=base,
start_with_empty_tuple=start_with_empty_tuple,method_name='getId') display_none_category=display_none_category,display_id='getId')
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getCategoryChildItemList') 'getCategoryChildItemList')
def getCategoryChildItemList(self, method_name = None, def getCategoryChildItemList(self, display_id = None,
recursive=1, base='', start_with_empty_tuple=0): recursive=1, base='', display_none_category=0):
""" """
Returns a list of tuples by parsing recursively all categories in a Returns a list of tuples by parsing recursively all categories in a
given list of base categories. Each tuple contains:: given list of base categories. Each tuple contains::
(c.relative_url,c.method_name()) (c.relative_url,c.display_id())
base -- if set to 1, relative_url will start with the base category id base -- if set to 1, relative_url will start with the base category id
if set to 0 and if base_category is a single id, relative_url if set to 0 and if base_category is a single id, relative_url
...@@ -221,38 +221,38 @@ class Category(Folder): ...@@ -221,38 +221,38 @@ class Category(Folder):
if set to string, use string as base if set to string, use string as base
method_name -- method called to build the couple display_id -- method called to build the couple
recursive -- if set to 0 do not apply recursively recursive -- if set to 0 do not apply recursively
""" """
if base == 0 or base is None: base = '' # Make sure we get a meaningful base if base == 0 or base is None: base = '' # Make sure we get a meaningful base
if base == 1: base = self.getBaseCategoryId() + '/' # Make sure we get a meaningful base if base == 1: base = self.getBaseCategoryId() + '/' # Make sure we get a meaningful base
if start_with_empty_tuple: if display_none_category:
s = [('', '')] s = [('', '')]
else: else:
s = [] s = []
if recursive: if recursive:
for c in self.objectValues(self.allowed_types): for c in self.objectValues(self.allowed_types):
s += c.getCategoryChildItemList(base=base + self.id + '/', s += c.getCategoryChildItemList(base=base + self.id + '/',
method_name = method_name, recursive = 1) display_id = display_id, recursive = 1)
else: else:
for c in self.objectValues(self.allowed_types): for c in self.objectValues(self.allowed_types):
if method_name is None: if display_id is None:
v = base + self.id + '/' + c.id v = base + self.id + '/' + c.id
s += [(v, base + self.id + '/' + c.id)] s += [(v, base + self.id + '/' + c.id)]
else: else:
try: try:
v = getattr(c, method_name)() v = getattr(c, display_id)()
s += [(v, base + self.id + '/' + c.id)] s += [(v, base + self.id + '/' + c.id)]
except: except:
LOG('WARNING: CategoriesTool',0, 'Unable to call %s on %s' % LOG('WARNING: CategoriesTool',0, 'Unable to call %s on %s' %
(method, c)) (method, c))
if method_name is None: if display_id is None:
v = base + self.id v = base + self.id
s = [(v, v)] + s s = [(v, v)] + s
else: else:
try: try:
v = getattr(self, method_name)() v = getattr(self, display_id)()
s = [(v, base + self.id)] + s s = [(v, base + self.id)] + s
except: except:
LOG('WARNING: CategoriesTool',0, 'Unable to call %s on %s' % LOG('WARNING: CategoriesTool',0, 'Unable to call %s on %s' %
...@@ -265,12 +265,12 @@ class Category(Folder): ...@@ -265,12 +265,12 @@ class Category(Folder):
""" """
Alias for compatibility and accelation Alias for compatibility and accelation
""" """
return self.getCategoryChildItemList(base=0,start_with_empty_tuple=1,recursive=1) return self.getCategoryChildItemList(base=0,display_none_category=1,recursive=1)
# Alias for compatibility # Alias for compatibility
security.declareProtected(Permissions.AccessContentsInformation, 'getBaseItemList') security.declareProtected(Permissions.AccessContentsInformation, 'getBaseItemList')
def getBaseItemList(self, base=0, prefix=''): def getBaseItemList(self, base=0, prefix=''):
return self.getCategoryChildItemList(base=base,start_with_empty_tuple=0,recursive=1) return self.getCategoryChildItemList(base=base,display_none_category=0,recursive=1)
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getCategoryRelativeUrl') 'getCategoryRelativeUrl')
...@@ -347,49 +347,54 @@ class Category(Folder): ...@@ -347,49 +347,54 @@ class Category(Folder):
return '/'.join(self.portal_url.getRelativeContentPath(self)[1:]) return '/'.join(self.portal_url.getRelativeContentPath(self)[1:])
security.declareProtected( Permissions.View, 'isMemberOf' ) security.declareProtected( Permissions.View, 'isMemberOf' )
def isMemberOf(self, category): def isMemberOf(self, category, strict = 0):
""" """
Tests if an object if member of a given category Tests if an object if member of a given category
Category is a string here. It could be more than a string (ex. an object) Category is a string here. It could be more than a string (ex. an object)
""" """
if self.getRelativeUrl().find(category) >= 0: if strict:
return 1 if self.getRelativeUrl().find(category) >= 0:
if len(category) == len(self.getRelativeUrl()) + len(self.getRelativeUrl().find(category)):
return 1
else:
if self.getRelativeUrl().find(category) >= 0:
return 1
return 0 return 0
security.declareProtected( Permissions.AccessContentsInformation, 'getCategoryMemberValueList' ) security.declareProtected( Permissions.AccessContentsInformation, 'getCategoryMemberValueList' )
def getCategoryMemberValueList(self, base_category_id = None, def getCategoryMemberValueList(self, base_category = None,
spec=(), filter=None, portal_type=(), strict = 0): spec=(), filter=None, portal_type=(), strict = 0):
""" """
Returns a list of objects or brains Returns a list of objects or brains
""" """
return self.portal_categories.getCategoryMemberValueList(self, return self.portal_categories.getCategoryMemberValueList(self,
base_category_id = base_category_id, base_category = base_category,
spec=spec, filter=filter, portal_type=portal_type,strict = strict) spec=spec, filter=filter, portal_type=portal_type,strict = strict)
security.declareProtected( Permissions.AccessContentsInformation, 'getCategoryMemberItemList' ) security.declareProtected( Permissions.AccessContentsInformation, 'getCategoryMemberItemList' )
def getCategoryMemberItemList(self, base_category_id = None, def getCategoryMemberItemList(self, base_category = None,
spec = (), filter=None, portal_type=(), strict = 0, method_name = None): spec = (), filter=None, portal_type=(), strict = 0, display_id = None):
""" """
Returns a list of objects or brains Returns a list of objects or brains
""" """
return self.portal_categories.getCategoryMemberItemList(self, return self.portal_categories.getCategoryMemberItemList(self,
base_category_id = base_category_id, spec=spec, base_category = base_category, spec=spec,
filter=filter, portal_type=portal_type, strict=strict, method_name=method_name) filter=filter, portal_type=portal_type, strict=strict, display_id=display_id)
security.declareProtected( Permissions.AccessContentsInformation, security.declareProtected( Permissions.AccessContentsInformation,
'getCategoryMemberTitleItemList' ) 'getCategoryMemberTitleItemList' )
def getCategoryMemberTitleItemList(self, base_category_id = None, def getCategoryMemberTitleItemList(self, base_category = None,
spec = (), filter=None, portal_type=(), strict = 0): spec = (), filter=None, portal_type=(), strict = 0):
""" """
Returns a list of objects or brains Returns a list of objects or brains
""" """
return self.portal_categories.getCategoryMemberItemList(self, return self.portal_categories.getCategoryMemberItemList(self,
base_category_id = base_category_id, base_category = base_category,
spec=spec, filter=filter, portal_type=portal_type,strict = strict, method_name = 'getTitle') spec=spec, filter=filter, portal_type=portal_type,strict = strict, display_id = 'getTitle')
...@@ -474,15 +479,15 @@ class BaseCategory(Category): ...@@ -474,15 +479,15 @@ class BaseCategory(Category):
""" """
return self return self
def getCategoryChildItemList(self, method_name = None, def getCategoryChildItemList(self, display_id = None,
recursive=1, base='', start_with_empty_tuple=0): recursive=1, base='', display_none_category=0):
""" """
Returns a list of tuples by parsing recursively all categories in a Returns a list of tuples by parsing recursively all categories in a
given list of base categories. Each tuple contains:: given list of base categories. Each tuple contains::
(c.relative_url,c.method_name()) (c.relative_url,c.display_id())
Because this is a base_category, we should not keep base_category_id unless Because this is a base_category, we should not keep base_category unless
required. required.
base -- if set to 1, relative_url will start with the base category id base -- if set to 1, relative_url will start with the base category id
...@@ -492,39 +497,39 @@ class BaseCategory(Category): ...@@ -492,39 +497,39 @@ class BaseCategory(Category):
if set to string, use string as base if set to string, use string as base
method_name -- method called to build the couple display_id -- method called to build the couple
recursive -- if set to 0 do not apply recursively recursive -- if set to 0 do not apply recursively
""" """
if base == 0 or base is None: base = '' # Make sure we get a meaningful base if base == 0 or base is None: base = '' # Make sure we get a meaningful base
if base == 1: base = self.id + '/' # Make sure we get a meaningful base if base == 1: base = self.id + '/' # Make sure we get a meaningful base
if start_with_empty_tuple: if display_none_category:
s = [('', '')] s = [('', '')]
else: else:
s = [] s = []
if recursive: if recursive:
for c in self.objectValues(self.allowed_types): for c in self.objectValues(self.allowed_types):
s += c.getCategoryChildItemList(base=base, s += c.getCategoryChildItemList(base=base,
method_name = method_name, recursive = 1) display_id = display_id, recursive = 1)
else: else:
for c in self.objectValues(self.allowed_types): for c in self.objectValues(self.allowed_types):
if method_name is None: if display_id is None:
v = base + self.id + '/' + c.id v = base + self.id + '/' + c.id
s += [(v, base + c.id)] s += [(v, base + c.id)]
else: else:
try: try:
v = getattr(o, method_name)() v = getattr(o, display_id)()
s += [(v, base + c.id)] s += [(v, base + c.id)]
except: except:
LOG('WARNING: CategoriesTool',0, 'Unable to call %s on %s' % LOG('WARNING: CategoriesTool',0, 'Unable to call %s on %s' %
(method, c)) (method, c))
if base is not '': if base is not '':
if method_name is None: if display_id is None:
v = base v = base
s = [(v, v)] + s s = [(v, v)] + s
else: else:
try: try:
v = getattr(self, method_name)() v = getattr(self, display_id)()
s = [(v, base)] + s s = [(v, base)] + s
except: except:
LOG('WARNING: CategoriesTool',0, 'Unable to call %s on %s' % LOG('WARNING: CategoriesTool',0, 'Unable to call %s on %s' %
......
...@@ -266,8 +266,8 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -266,8 +266,8 @@ class CategoryTool( UniqueObject, Folder, Base ):
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:
base_category_id = self.getBaseCategoryId(path) base_category = self.getBaseCategoryId(path)
bo = self.get(base_category_id, None) bo = self.get(base_category, None)
if bo is not None: if bo is not None:
bo_uid = int(bo.getUid()) bo_uid = int(bo.getUid())
uid_dict[(int(o.uid), bo_uid, 1)] = 1 # Strict Membership uid_dict[(int(o.uid), bo_uid, 1)] = 1 # Strict Membership
...@@ -337,34 +337,34 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -337,34 +337,34 @@ class CategoryTool( UniqueObject, Folder, Base ):
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getCategoryChildTitleItemList') 'getCategoryChildTitleItemList')
def getCategoryChildTitleItemList(self, base_category=None, def getCategoryChildTitleItemList(self, base_category=None,
recursive=1, base=0, start_with_empty_tuple=0, sort_id=None): recursive=1, base=0, display_none_category=0, sort_id=None):
""" """
Returns a list of tuples by parsing recursively all categories in a Returns a list of tuples by parsing recursively all categories in a
given list of base categories. Uses getTitle as default method given list of base categories. Uses getTitle as default method
""" """
return self.getCategoryChildItemList(recursive = recursive,base=base, return self.getCategoryChildItemList(recursive = recursive,base=base,
start_with_empty_tuple=start_with_empty_tuple,method_name='getTitle', sort_id=sort_id) display_none_category=display_none_category,display_id='getTitle', sort_id=sort_id)
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getCategoryChildIdItemList') 'getCategoryChildIdItemList')
def getCategoryChildIdItemList(self, base_category=None, def getCategoryChildIdItemList(self, base_category=None,
recursive=1, base=0, start_with_empty_tuple=0, sort_id=None): recursive=1, base=0, display_none_category=0, sort_id=None):
""" """
Returns a list of tuples by parsing recursively all categories in a Returns a list of tuples by parsing recursively all categories in a
given list of base categories. Uses getId as default method given list of base categories. Uses getId as default method
""" """
return self.getCategoryChildItemList(recursive = recursive,base=base, return self.getCategoryChildItemList(recursive = recursive,base=base,
start_with_empty_tuple=start_with_empty_tuple,method_name='getId', sort_id=sort_id) display_none_category=display_none_category,display_id='getId', sort_id=sort_id)
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getCategoryChildItemList') 'getCategoryChildItemList')
def getCategoryChildItemList(self, base_category=None, method_name = None, def getCategoryChildItemList(self, base_category=None, display_id = None,
recursive=1, base=0, start_with_empty_tuple=1, sort_id=None): recursive=1, base=0, display_none_category=1, sort_id=None):
""" """
Returns a list of tuples by parsing recursively all categories in a Returns a list of tuples by parsing recursively all categories in a
given list of base categories. Each tuple contains:: given list of base categories. Each tuple contains::
(c.relative_url,c.method_name()) (c.relative_url,c.display_id())
base_category -- A single base category id or a list of base category ids base_category -- A single base category id or a list of base category ids
if not provided, base category will be set with the list if not provided, base category will be set with the list
...@@ -375,7 +375,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -375,7 +375,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
are relative to the base_category (and thus doesn't start are relative to the base_category (and thus doesn't start
with the base category id) with the base category id)
method_name -- method called to build the couple display_id -- method called to build the couple
recursive -- if set to 0 do not apply recursively recursive -- if set to 0 do not apply recursively
""" """
...@@ -385,7 +385,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -385,7 +385,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
base_category_list = self.getBaseCategoryIdList() base_category_list = self.getBaseCategoryIdList()
else: else:
base_category_list = base_category base_category_list = base_category
if start_with_empty_tuple: if display_none_category:
result = [('', '')] result = [('', '')]
else: else:
result = [] result = []
...@@ -393,7 +393,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -393,7 +393,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
category = self[base_category] category = self[base_category]
if category is not None: if category is not None:
result += category.getCategoryChildItemList(base=base,recursive=recursive, result += category.getCategoryChildItemList(base=base,recursive=recursive,
method_name=method_name) display_id=display_id)
#if sort_id is not None: #if sort_id is not None:
# result.sort() # result.sort()
...@@ -405,10 +405,10 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -405,10 +405,10 @@ class CategoryTool( UniqueObject, Folder, Base ):
# Category to Tuple Conversion # Category to Tuple Conversion
security.declareProtected(Permissions.View, 'asItemList') security.declareProtected(Permissions.View, 'asItemList')
def asItemList(self, relative_url, base_category=None, def asItemList(self, relative_url, base_category=None,
method_name = None, base = 0, sort_id=None): display_id = None, base = 0, sort_id=None):
""" """
Returns a list of tuples, each tuple is calculated by applying Returns a list of tuples, each tuple is calculated by applying
method_name on each category provided in relative_url display_id on each category provided in relative_url
base_category -- A single base category id or a list of base category ids base_category -- A single base category id or a list of base category ids
if not provided, base category will be set with the list if not provided, base category will be set with the list
...@@ -419,12 +419,12 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -419,12 +419,12 @@ class CategoryTool( UniqueObject, Folder, Base ):
are relative to the base_category (and thus doesn't start are relative to the base_category (and thus doesn't start
with the base category id) with the base category id)
method_name -- method called to build the couple display_id -- method called to build the couple
recursive -- if set to 0 do not apply recursively recursive -- if set to 0 do not apply recursively
""" """
result = [] result = []
if method_name is None: if display_id is None:
for c in relative_url: for c in relative_url:
result += [(c, c)] result += [(c, c)]
else: else:
...@@ -432,7 +432,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -432,7 +432,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
o = self.getCategoryValue(c, base_category=base_category) o = self.getCategoryValue(c, base_category=base_category)
if o is not None: if o is not None:
try: try:
v = getattr(o, method_name)() v = getattr(o, display_id)()
result = result + [(c,v)] result = result + [(c,v)]
except: except:
LOG('WARNING: CategoriesTool',0, 'Unable to call %s on %s' % LOG('WARNING: CategoriesTool',0, 'Unable to call %s on %s' %
...@@ -655,7 +655,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -655,7 +655,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
security.declareProtected( Permissions.AccessContentsInformation, security.declareProtected( Permissions.AccessContentsInformation,
'getSingleCategoryMembershipList' ) 'getSingleCategoryMembershipList' )
def getSingleCategoryMembershipList(self, context, base_category_id, base=0, def getSingleCategoryMembershipList(self, context, base_category, base=0,
spec=(), filter=None, **kw): spec=(), filter=None, **kw):
""" """
Returns the local membership of the context for a single base category Returns the local membership of the context for a single base category
...@@ -686,9 +686,9 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -686,9 +686,9 @@ class CategoryTool( UniqueObject, Folder, Base ):
if hasattr(context, 'categories'): if hasattr(context, 'categories'):
for category_url in self._getCategoryList(context): for category_url in self._getCategoryList(context):
my_base_category = category_url.split('/')[0] my_base_category = category_url.split('/')[0]
if my_base_category == base_category_id: if my_base_category == base_category:
#LOG("getSingleCategoryMembershipList",0,"%s %s %s %s" % (context.getRelativeUrl(), #LOG("getSingleCategoryMembershipList",0,"%s %s %s %s" % (context.getRelativeUrl(),
# my_base_category, base_category_id, category_url)) # my_base_category, base_category, category_url))
if spec is (): if spec is ():
if base: if base:
result += [category_url] result += [category_url]
...@@ -711,7 +711,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -711,7 +711,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
security.declareProtected( Permissions.AccessContentsInformation, security.declareProtected( Permissions.AccessContentsInformation,
'getSingleCategoryAcquiredMembershipList' ) 'getSingleCategoryAcquiredMembershipList' )
def getSingleCategoryAcquiredMembershipList(self, context, base_category_id, base=0, def getSingleCategoryAcquiredMembershipList(self, context, base_category, base=0,
spec=(), filter=None, **kw ): spec=(), filter=None, **kw ):
""" """
Returns the acquired membership of the context for a single base category Returns the acquired membership of the context for a single base category
...@@ -726,7 +726,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -726,7 +726,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
base -- if set to 1, returns relative URLs to portal_categories base -- if set to 1, returns relative URLs to portal_categories
if set to 0, returns relative URLs to the base category if set to 0, returns relative URLs to the base category
""" """
#LOG("Get Acquired Category ",0,str((base_category_id, context))) #LOG("Get Acquired Category ",0,str((base_category, context)))
# XXX We must use filters in the future # XXX We must use filters in the future
# query = self._buildQuery(spec, filter, kw) # query = self._buildQuery(spec, filter, kw)
portal_type = kw.get('portal_type', ()) portal_type = kw.get('portal_type', ())
...@@ -734,9 +734,9 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -734,9 +734,9 @@ class CategoryTool( UniqueObject, Folder, Base ):
if type(spec) is type('a'): if type(spec) is type('a'):
spec = [spec] spec = [spec]
result = self.getSingleCategoryMembershipList( context, base_category_id, base=base, result = self.getSingleCategoryMembershipList( context, base_category, base=base,
spec=spec, filter=filter, **kw ) spec=spec, filter=filter, **kw )
base_category = self.getCategoryValue(base_category_id) base_category = self.getCategoryValue(base_category)
if base_category is not None: if base_category is not None:
# If we do not mask or append, return now if not empty # If we do not mask or append, return now if not empty
if not base_category.getAcquisitionMaskValue() and \ if not base_category.getAcquisitionMaskValue() and \
...@@ -749,7 +749,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -749,7 +749,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
if my_acquisition_object is not None: if my_acquisition_object is not None:
if spec is () or my_acquisition_object.portal_type in spec: if spec is () or my_acquisition_object.portal_type in spec:
new_result = self.getSingleCategoryMembershipList(my_acquisition_object, new_result = self.getSingleCategoryMembershipList(my_acquisition_object,
base_category_id, spec=spec, filter=filter, portal_type=portal_type, base=base) base_category, spec=spec, filter=filter, portal_type=portal_type, base=base)
if base_category.acquisition_mask_value: if base_category.acquisition_mask_value:
# If acquisition masks, then we must return now # If acquisition masks, then we must return now
return new_result return new_result
...@@ -759,9 +759,9 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -759,9 +759,9 @@ class CategoryTool( UniqueObject, Folder, Base ):
# Next we look at references # Next we look at references
#LOG("Get Acquired BC",0,str(base_category.getAcquisitionBaseCategoryList())) #LOG("Get Acquired BC",0,str(base_category.getAcquisitionBaseCategoryList()))
acquisition_pt = base_category.getAcquisitionPortalTypeList(()) acquisition_pt = base_category.getAcquisitionPortalTypeList(())
for my_base_category_id in base_category.getAcquisitionBaseCategoryList(): for my_base_category in base_category.getAcquisitionBaseCategoryList():
# We implement here special keywords # We implement here special keywords
if my_base_category_id == 'parent': if my_base_category == 'parent':
parent = context.aq_parent parent = context.aq_parent
if parent is self.getPortalObject(): if parent is self.getPortalObject():
my_acquisition_object_list = [] my_acquisition_object_list = []
...@@ -774,7 +774,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -774,7 +774,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
else: else:
my_acquisition_object_list = [] my_acquisition_object_list = []
else: else:
my_acquisition_object_list = context.getValueList(my_base_category_id, my_acquisition_object_list = context.getValueList(my_base_category,
portal_type=tuple(base_category.getAcquisitionPortalTypeList(()))) portal_type=tuple(base_category.getAcquisitionPortalTypeList(())))
#LOG("Get Acquired PT",0,str(base_category.getAcquisitionPortalTypeList(()))) #LOG("Get Acquired PT",0,str(base_category.getAcquisitionPortalTypeList(())))
#LOG("Object List ",0,str(my_acquisition_object_list)) #LOG("Object List ",0,str(my_acquisition_object_list))
...@@ -784,10 +784,10 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -784,10 +784,10 @@ class CategoryTool( UniqueObject, Folder, Base ):
if my_acquisition_object is not None: if my_acquisition_object is not None:
if hasattr(my_acquisition_object, '_categories'): if hasattr(my_acquisition_object, '_categories'):
# We should only consider objects which define that category # We should only consider objects which define that category
if base_category_id in my_acquisition_object._categories: if base_category in my_acquisition_object._categories:
if spec is () or my_acquisition_object.portal_type in spec: if spec is () or my_acquisition_object.portal_type in spec:
new_result = self.getSingleCategoryAcquiredMembershipList(my_acquisition_object, new_result = self.getSingleCategoryAcquiredMembershipList(my_acquisition_object,
base_category_id, spec=spec, filter=filter, portal_type=portal_type, base=base) base_category, spec=spec, filter=filter, portal_type=portal_type, base=base)
else: else:
new_result = [] new_result = []
if base_category.acquisition_append_value: if base_category.acquisition_append_value:
...@@ -798,7 +798,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -798,7 +798,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
or base_category.acquisition_sync_value: or base_category.acquisition_sync_value:
# If copy is set and result was empty, then copy it once # If copy is set and result was empty, then copy it once
# If sync is set, then copy it again # If sync is set, then copy it again
self.setCategoryMembership( context, base_category_id, new_result, self.setCategoryMembership( context, base_category, new_result,
spec=spec, filter=filter, portal_type=portal_type, base=base ) spec=spec, filter=filter, portal_type=portal_type, base=base )
# We found it, we can return # We found it, we can return
return new_result return new_result
...@@ -806,7 +806,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -806,7 +806,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
and len(result) > 0: and len(result) > 0:
# If copy is set and result was empty, then copy it once # If copy is set and result was empty, then copy it once
# If sync is set, then copy it again # If sync is set, then copy it again
self.setCategoryMembership( context, base_category_id, result, self.setCategoryMembership( context, base_category, result,
spec=spec, filter=filter, portal_type=portal_type, base=base ) spec=spec, filter=filter, portal_type=portal_type, base=base )
# WE MUST IMPLEMENT HERE THE REST OF THE SEMANTICS # WE MUST IMPLEMENT HERE THE REST OF THE SEMANTICS
#LOG("Get Acquired Category Result ",0,str(result)) #LOG("Get Acquired Category Result ",0,str(result))
...@@ -814,26 +814,26 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -814,26 +814,26 @@ class CategoryTool( UniqueObject, Folder, Base ):
security.declareProtected( Permissions.AccessContentsInformation, security.declareProtected( Permissions.AccessContentsInformation,
'getAcquiredCategoryMembershipList' ) 'getAcquiredCategoryMembershipList' )
def getAcquiredCategoryMembershipList(self, context, base_category_id = None, base=1, def getAcquiredCategoryMembershipList(self, context, base_category = None, base=1,
spec=(), filter=None, **kw): spec=(), filter=None, **kw):
""" """
Returns all acquired category values Returns all acquired category values
""" """
#LOG("Get Acquired Category", 0, "%s %s" % (base_category_id, context.getRelativeUrl())) #LOG("Get Acquired Category", 0, "%s %s" % (base_category, context.getRelativeUrl()))
result = [] result = []
if base_category_id is None: if base_category is None:
base_category_id_list = context._categories base_category_list = context._categories
elif type(base_category_id) is type('a'): elif type(base_category) is type('a'):
base_category_id_list = [base_category_id] base_category_list = [base_category]
else: else:
base_category_id_list = base_category_id base_category_list = base_category
for base_category_id in base_category_id_list: for base_category in base_category_list:
result += self.getSingleCategoryAcquiredMembershipList(context, base_category_id, base=base, result += self.getSingleCategoryAcquiredMembershipList(context, base_category, base=base,
spec=spec, filter=filter, **kw ) spec=spec, filter=filter, **kw )
return result return result
security.declareProtected( Permissions.AccessContentsInformation, 'isMemberOf' ) security.declareProtected( Permissions.AccessContentsInformation, 'isMemberOf' )
def isMemberOf(self, context, category): def isMemberOf(self, context, category, strict=0):
""" """
Tests if an object if member of a given category Tests if an object if member of a given category
Category is a string here. It could be more than a string (ex. an object) Category is a string here. It could be more than a string (ex. an object)
...@@ -841,10 +841,15 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -841,10 +841,15 @@ class CategoryTool( UniqueObject, Folder, Base ):
XXX Should include acquisition ? XXX Should include acquisition ?
""" """
if getattr(aq_base(context), 'isCategory', 0): if getattr(aq_base(context), 'isCategory', 0):
return context.isMemberOf(category) return context.isMemberOf(category, strict=strict)
for c in self._getCategoryList(context): if strict:
if c.find(category) >= 0: for c in self._getCategoryList(context):
return 1 if c.find(category) >= 0:
return 1
else:
for c in self._getCategoryList(context):
if c == category:
return 1
return 0 return 0
security.declareProtected( Permissions.AccessContentsInformation, 'getCategoryList' ) security.declareProtected( Permissions.AccessContentsInformation, 'getCategoryList' )
...@@ -884,7 +889,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -884,7 +889,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
security.declareProtected( Permissions.AccessContentsInformation, '_getAcquiredCategoryList' ) security.declareProtected( Permissions.AccessContentsInformation, '_getAcquiredCategoryList' )
def _getAcquiredCategoryList(self, context): def _getAcquiredCategoryList(self, context):
result = self.getAcquiredCategoryMembershipList(context, result = self.getAcquiredCategoryMembershipList(context,
base_category_id = self.getBaseCategoryIdList(context=context)) base_category = self.getBaseCategoryIdList(context=context))
if getattr(context, 'isCategory', 0): if getattr(context, 'isCategory', 0):
result = tuple(list(result) + [context.getRelativeUrl()]) # Pure category is member of itself result = tuple(list(result) + [context.getRelativeUrl()]) # Pure category is member of itself
return result return result
...@@ -930,24 +935,24 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -930,24 +935,24 @@ class CategoryTool( UniqueObject, Folder, Base ):
self.updateRelatedContent(o, previous_o_category_url, new_o_category_url) self.updateRelatedContent(o, previous_o_category_url, new_o_category_url)
security.declareProtected( Permissions.ModifyPortalContent, 'getRelatedValueList' ) security.declareProtected( Permissions.ModifyPortalContent, 'getRelatedValueList' )
def getRelatedValueList(self, context, base_category_id_list, def getRelatedValueList(self, context, base_category_list,
spec=(), filter=None, base=1, **kw): spec=(), filter=None, base=1, **kw):
#LOG('getRelatedValueList',0,'base_category_id_list: %s, filter: %s, kw: %s' % #LOG('getRelatedValueList',0,'base_category_list: %s, filter: %s, kw: %s' %
# (str(base_category_id_list),str(filter),str(kw))) # (str(base_category_list),str(filter),str(kw)))
portal_type = kw.get('portal_type') portal_type = kw.get('portal_type')
if type(portal_type) is type('a'): if type(portal_type) is type('a'):
portal_type = [portal_type] portal_type = [portal_type]
if spec is (): spec = None # We do not want to care about spec if spec is (): spec = None # We do not want to care about spec
if type(base_category_id_list) is type('a'): if type(base_category_list) is type('a'):
base_category_id_list = [base_category_id_list] base_category_list = [base_category_list]
elif base_category_id_list is () or base_category_id_list is None: elif base_category_list is () or base_category_list is None:
base_category_id_list = self.getBaseCategoryIdList() base_category_list = self.getBaseCategoryIdList()
category_list = [] category_list = []
#LOG('getRelatedValueList',0,'base_category_id_list: %s' % str(base_category_id_list)) #LOG('getRelatedValueList',0,'base_category_list: %s' % str(base_category_list))
for base_category_id in base_category_id_list: for base_category in base_category_list:
category_list += ["%s/%s" % (base_category_id, context.getRelativeUrl())] category_list += ["%s/%s" % (base_category, context.getRelativeUrl())]
brain_result = self.search_category(category_list = category_list, brain_result = self.search_category(category_list = category_list,
portal_type = portal_type ) portal_type = portal_type )
...@@ -1007,7 +1012,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -1007,7 +1012,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
security.declareProtected( Permissions.AccessContentsInformation, 'getCategoryMemberValueList' ) security.declareProtected( Permissions.AccessContentsInformation, 'getCategoryMemberValueList' )
def getCategoryMemberValueList(self, context, base_category_id = None, def getCategoryMemberValueList(self, context, base_category = None,
spec = (), filter=None, portal_type=(), strict = 0): spec = (), filter=None, portal_type=(), strict = 0):
""" """
This returns a catalog_search resource with can then be used by getCategoryMemberItemList This returns a catalog_search resource with can then be used by getCategoryMemberItemList
...@@ -1026,32 +1031,32 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -1026,32 +1031,32 @@ class CategoryTool( UniqueObject, Folder, Base ):
security.declareProtected( Permissions.AccessContentsInformation, 'getCategoryMemberItemList' ) security.declareProtected( Permissions.AccessContentsInformation, 'getCategoryMemberItemList' )
def getCategoryMemberItemList(self, context, base_category_id = None, def getCategoryMemberItemList(self, context, base_category = None,
spec = (), filter=None, portal_type=(), strict = 0, method_name = None, sort_id=None): spec = (), filter=None, portal_type=(), strict = 0, display_id = None, sort_id=None):
""" """
This returns with "method_name" method a list of items belonging to a category This returns with "display_id" method a list of items belonging to a category
""" """
result = [] result = []
if base_category_id is None: if base_category is None:
base = '' base = ''
else: else:
base = base_category_id + '/' base = base_category + '/'
catalog_search = self.getCategoryMemberValueList(context) catalog_search = self.getCategoryMemberValueList(context)
for b in catalog_search: for b in catalog_search:
if method_name is None: if display_id is None:
v = base + b.relative_url v = base + b.relative_url
result += [(v,v)] result += [(v,v)]
else: else:
try: try:
o = b.getObject() o = b.getObject()
v = getattr(o, method_name)() v = getattr(o, display_id)()
result += [(v,base + b.relative_url)] result += [(v,base + b.relative_url)]
except: except:
LOG('WARNING: CategoriesTool',0, 'Unable to call %s on %s' % (method_name, b)) LOG('WARNING: CategoriesTool',0, 'Unable to call %s on %s' % (display_id, b))
if sort_id is not None: if sort_id is not None:
result.sort() result.sort()
...@@ -1060,14 +1065,14 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -1060,14 +1065,14 @@ class CategoryTool( UniqueObject, Folder, Base ):
security.declareProtected( Permissions.AccessContentsInformation, security.declareProtected( Permissions.AccessContentsInformation,
'getCategoryMemberTitleItemList' ) 'getCategoryMemberTitleItemList' )
def getCategoryMemberTitleItemList(self, context, base_category_id = None, def getCategoryMemberTitleItemList(self, context, base_category = None,
spec = (), filter=None, portal_type=(), strict = 0): spec = (), filter=None, portal_type=(), strict = 0):
""" """
This returns a title list of items belonging to a category This returns a title list of items belonging to a category
""" """
getCategoryMemberItemList(self, context, base_category_id = base_category_id, getCategoryMemberItemList(self, context, base_category = base_category,
spec = spec, filter=filter, portal_type=portal_type, strict = strict, method_name = 'getTitle') spec = spec, filter=filter, portal_type=portal_type, strict = strict, display_id = 'getTitle')
security.declarePrivate('resolveCategory') security.declarePrivate('resolveCategory')
......
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