Commit 26ca36e1 authored by Jean-Paul Smets's avatar Jean-Paul Smets

New version based on Renderer


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@1176 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 4ef29015
...@@ -35,6 +35,7 @@ from Acquisition import aq_base, aq_inner, aq_parent ...@@ -35,6 +35,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.Folder import Folder
from Products.CMFCategory.Renderer import Renderer
from zLOG import LOG from zLOG import LOG
...@@ -157,6 +158,23 @@ class Category(Folder): ...@@ -157,6 +158,23 @@ class Category(Folder):
else: else:
return self.getCategoryRelativeUrl() return self.getCategoryRelativeUrl()
security.declareProtected(Permissions.AccessContentsInformation,
'getCategoryChildValueList')
def getCategoryChildValueList(self, recursive=1):
"""
List the child objects of this category and all its subcategories.
recursive - if set to 1, list recursively
"""
value_list = [self]
if recursive:
for c in self.objectValues(self.allowed_types):
value_list.extend(c.getCategoryChildValueList(recursive = 1))
else:
for c in self.objectValues(self.allowed_types):
value_list.append(c)
return value_list
# List names recursively # List names recursively
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getCategoryChildRelativeUrlList') 'getCategoryChildRelativeUrlList')
...@@ -171,43 +189,36 @@ class Category(Folder): ...@@ -171,43 +189,36 @@ class Category(Folder):
""" """
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
s = '' url_list = []
if recursive: for value in self.getCategoryChildValueList(recursive = recursive):
for c in self.objectValues(self.allowed_types): url_list.append(base + value.getRelativeUrl())
s += c.getCategoryChildRelativeUrlList(base=base + self.id + '/', recursive = 1) return url_list
else:
for c in self.objectValues(self.allowed_types):
s += base + self.id + '/' + c.id + '\n'
return base + self.id + '\n' + s
security.declareProtected(Permissions.AccessContentsInformation, 'getPathList') security.declareProtected(Permissions.AccessContentsInformation, 'getPathList')
getPathList = getCategoryChildRelativeUrlList getPathList = getCategoryChildRelativeUrlList
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getCategoryChildTitleItemList') 'getCategoryChildTitleItemList')
def getCategoryChildTitleItemList(self, recursive=1, base='', display_none_category=0): def getCategoryChildTitleItemList(self, recursive=1, **kw):
""" """
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, display_id='getTitle', **kw)
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='', display_none_category=0): def getCategoryChildIdItemList(self, recursive=1, **kw):
""" """
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, display_id='getId', **kw)
display_none_category=display_none_category,display_id='getId')
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getCategoryChildItemList') 'getCategoryChildItemList')
def getCategoryChildItemList(self, display_id = None, def getCategoryChildItemList(self, recursive=1, **kw):
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::
...@@ -225,39 +236,9 @@ class Category(Folder): ...@@ -225,39 +236,9 @@ class Category(Folder):
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 LOG('getCategoryChildItemList', 0, 'kw = %s, recursive = %s' % (str(kw), str(recursive)))
if base == 1: base = self.getBaseCategoryId() + '/' # Make sure we get a meaningful base value_list = self.getCategoryChildValueList(recursive=recursive)
if display_none_category: return Renderer(**kw).render(value_list)
s = [('', '')]
else:
s = []
if recursive:
for c in self.objectValues(self.allowed_types):
s += c.getCategoryChildItemList(base=base + self.id + '/',
display_id = display_id, recursive = 1)
else:
for c in self.objectValues(self.allowed_types):
if display_id is None:
v = base + self.id + '/' + c.id
s += [(v, base + self.id + '/' + c.id)]
else:
try:
v = getattr(c, display_id)()
s += [(v, base + self.id + '/' + c.id)]
except:
LOG('WARNING: CategoriesTool',0, 'Unable to call %s on %s' %
(method, c))
if display_id is None:
v = base + self.id
s = [(v, v)] + s
else:
try:
v = getattr(self, display_id)()
s = [(v, base + self.id)] + s
except:
LOG('WARNING: CategoriesTool',0, 'Unable to call %s on %s' %
(method, c))
return s
# Alias for compatibility # Alias for compatibility
security.declareProtected(Permissions.View, 'getFormItemList') security.declareProtected(Permissions.View, 'getFormItemList')
...@@ -390,6 +371,17 @@ class Category(Folder): ...@@ -390,6 +371,17 @@ class Category(Folder):
kw['display_method'] = None kw['display_method'] = None
return self.portal_categories.getCategoryMemberItemList(self, **kw) return self.portal_categories.getCategoryMemberItemList(self, **kw)
security.declareProtected( Permissions.AccessContentsInformation, 'getBreadcrumbList' )
def getBreadcrumbList(self):
"""
Returns a list of objects or brains
"""
title_list = []
if not self.isBaseCategory:
title_list.extend(self.aq_parent.getBreadcrumbList())
title_list.append(self.getTitle())
return title_list
manage_addBaseCategoryForm=DTMLFile('dtml/base_category_add', globals()) manage_addBaseCategoryForm=DTMLFile('dtml/base_category_add', globals())
def addBaseCategory( self, id, title='', REQUEST=None ): def addBaseCategory( self, id, title='', REQUEST=None ):
...@@ -471,62 +463,22 @@ class BaseCategory(Category): ...@@ -471,62 +463,22 @@ class BaseCategory(Category):
""" """
return self return self
def getCategoryChildItemList(self, display_id = None, security.declareProtected(Permissions.AccessContentsInformation,
recursive=1, base='', display_none_category=0): 'getCategoryChildValueList')
def getCategoryChildValueList(self, recursive=1):
""" """
Returns a list of tuples by parsing recursively all categories in a List the child objects of this category and all its subcategories.
given list of base categories. Each tuple contains::
(c.relative_url,c.display_id())
Because this is a base_category, we should not keep base_category unless
required.
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
are relative to the base_category (and thus doesn't start
with the base category id)
if set to string, use string as base
display_id -- method called to build the couple
recursive -- if set to 0 do not apply recursively recursive - if set to 1, list recursively
""" """
if base == 0 or base is None: base = '' # Make sure we get a meaningful base value_list = []
if base == 1: base = self.id + '/' # Make sure we get a meaningful base
if display_none_category:
s = [('', '')]
else:
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, value_list.extend(c.getCategoryChildValueList(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 display_id is None: value_list.append(c)
v = base + self.id + '/' + c.id return value_list
s += [(v, base + c.id)]
else:
try:
v = getattr(o, display_id)()
s += [(v, base + c.id)]
except:
LOG('WARNING: CategoriesTool',0, 'Unable to call %s on %s' %
(method, c))
if base is not '':
if display_id is None:
v = base
s = [(v, v)] + s
else:
try:
v = getattr(self, display_id)()
s = [(v, base)] + s
except:
LOG('WARNING: CategoriesTool',0, 'Unable to call %s on %s' %
(method, c))
return s
# Alias for compatibility # Alias for compatibility
security.declareProtected( Permissions.AccessContentsInformation, 'getBaseCategory' ) security.declareProtected( Permissions.AccessContentsInformation, 'getBaseCategory' )
......
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