Commit 8f9cfdf3 authored by Jérome Perrin's avatar Jérome Perrin

BaseCategory.getCategoryChildValueList is not returning self in the list,...

BaseCategory.getCategoryChildValueList is not returning self in the list, Category.getCategoryChildValueList was.
Make this consitent by changing Category.getCategoryChildValueList not to include self by default.



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@13586 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 8bdcebf8
...@@ -214,7 +214,7 @@ class Category(Folder): ...@@ -214,7 +214,7 @@ class Category(Folder):
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getCategoryChildValueList') 'getCategoryChildValueList')
def getCategoryChildValueList(self, recursive=1, include_if_child=1, def getCategoryChildValueList(self, recursive=1, include_if_child=1,
is_self_excluded=0, sort_on=None, is_self_excluded=1, sort_on=None,
sort_order=None, **kw): sort_order=None, **kw):
""" """
List the child objects of this category and all its subcategories. List the child objects of this category and all its subcategories.
...@@ -245,6 +245,7 @@ class Category(Folder): ...@@ -245,6 +245,7 @@ class Category(Folder):
# Do not pass sort parameters intentionally, because sorting # Do not pass sort parameters intentionally, because sorting
# needs to be done only at the end of recursive calls. # needs to be done only at the end of recursive calls.
value_list.extend(c.getCategoryChildValueList(recursive=1, value_list.extend(c.getCategoryChildValueList(recursive=1,
is_self_excluded=0,
include_if_child=include_if_child)) include_if_child=include_if_child))
else: else:
for c in self.objectValues(self.allowed_types): for c in self.objectValues(self.allowed_types):
...@@ -377,7 +378,7 @@ class Category(Folder): ...@@ -377,7 +378,7 @@ class Category(Folder):
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.display_id()) (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
...@@ -668,12 +669,14 @@ class BaseCategory(Category): ...@@ -668,12 +669,14 @@ class BaseCategory(Category):
... ...
""" """
if is_self_excluded:
value_list = [] value_list = []
if not is_self_excluded: else:
value_list = [self] value_list = [self]
if recursive: if recursive:
for c in self.objectValues(self.allowed_types): for c in self.objectValues(self.allowed_types):
value_list.extend(c.getCategoryChildValueList(recursive=1, value_list.extend(c.getCategoryChildValueList(recursive=1,
is_self_excluded=0,
include_if_child=include_if_child)) include_if_child=include_if_child))
else: else:
for c in self.objectValues(self.allowed_types): for c in self.objectValues(self.allowed_types):
......
...@@ -802,6 +802,39 @@ class TestCMFCategory(ERP5TypeTestCase): ...@@ -802,6 +802,39 @@ class TestCMFCategory(ERP5TypeTestCase):
self.assertEqual(e.args[0], 'Category must be of string, tuple of ' self.assertEqual(e.args[0], 'Category must be of string, tuple of '
'string or list of string type.') 'string or list of string type.')
def test_23_getCategoryChildValueList(self, quiet=quiet, run=run_all_test) :
if not run: return
if not quiet:
message = 'Test getCategoryChildValueList and arguments'
ZopeTestCase._print('\n '+message)
LOG('Testing... ', 0, message)
pc = self.getCategoriesTool()
bc = pc.newContent(portal_type='Base Category', id='child_test')
c1 = bc.newContent(portal_type='Category', id='1')
c11 = c1.newContent(portal_type='Category', id='1.1')
c111 = c11.newContent(portal_type='Category', id='1.1.1')
c2 = bc.newContent(portal_type='Category', id='2')
self.assertSameSet(bc.getCategoryChildValueList(), (c1, c11, c111, c2))
self.assertSameSet(c1.getCategoryChildValueList(), (c11, c111,))
# recursive
self.assertSameSet(bc.getCategoryChildValueList(recursive=0), (c1, c2))
self.assertSameSet(c1.getCategoryChildValueList(recursive=0), (c11, ))
# only leaves
self.assertSameSet(bc.getCategoryChildValueList(include_if_child=0),
(c111, c2))
self.assertSameSet(c1.getCategoryChildValueList(include_if_child=0),
(c111, ))
# including self
self.assertSameSet(bc.getCategoryChildValueList(is_self_excluded=0),
(bc, c1, c11, c111, c2))
self.assertSameSet(c1.getCategoryChildValueList(is_self_excluded=0),
(c1, c11, c111))
if __name__ == '__main__': if __name__ == '__main__':
framework() framework()
else: else:
......
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