Commit f2721106 authored by Yoshinori Okuji's avatar Yoshinori Okuji

Cleanup and bugfix on setCategoryMembership. Now portal_type-based coloring is working.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@4087 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 0b853cab
...@@ -573,7 +573,10 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -573,7 +573,10 @@ class CategoryTool( UniqueObject, Folder, Base ):
# XXX We must use filters in the future # XXX We must use filters in the future
# where_expression = self._buildQuery(spec, filter, kw) # where_expression = self._buildQuery(spec, filter, kw)
portal_type = kw.get('portal_type', ()) portal_type = kw.get('portal_type', ())
if spec is (): spec = portal_type if type(portal_type) == type(''):
portal_type = (portal_type,)
if spec is ():
spec = portal_type
#LOG("set Category",0,str(category_list)) #LOG("set Category",0,str(category_list))
default_dict = {} default_dict = {}
...@@ -590,7 +593,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -590,7 +593,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
if not my_base_id in base_category_list: if not my_base_id in base_category_list:
# Keep each membership which is not in the # Keep each membership which is not in the
# specified list of base_category ids # specified list of base_category ids
new_category_list += [path] new_category_list.append(path)
else: else:
if spec is (): if spec is ():
# If spec is (), then we should keep nothing # If spec is (), then we should keep nothing
...@@ -600,14 +603,11 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -600,14 +603,11 @@ class CategoryTool( UniqueObject, Folder, Base ):
# Only keep this if not in our spec # Only keep this if not in our spec
try: try:
my_type = self.unrestrictedTraverse(path).portal_type my_type = self.unrestrictedTraverse(path).portal_type
keep_it = 1 keep_it = (my_type not in spec)
for spec_type in spec:
if spec_type == my_type:
keep_it = 0
except (KeyError, AttributeError): except (KeyError, AttributeError):
keep_it = 0 keep_it = 0
if keep_it: if keep_it:
new_category_list += [path] new_category_list.append(path)
elif keep_default: elif keep_default:
# We must remember the default value # We must remember the default value
# for each replaced category # for each replaced category
...@@ -618,25 +618,25 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -618,25 +618,25 @@ class CategoryTool( UniqueObject, Folder, Base ):
for path in default_dict.values(): for path in default_dict.values():
if base or len(base_category_list) > 1: if base or len(base_category_list) > 1:
if path in category_list: if path in category_list:
default_new_category_list += [path] default_new_category_list.append(path)
else: else:
if path[len(base_category_list[0])+1:] in category_list: if path[len(base_category_list[0])+1:] in category_list:
default_new_category_list += [path] default_new_category_list.append(path)
# Before we append new category values (except default values) # Before we append new category values (except default values)
# We must make sure however that multiple links are possible # We must make sure however that multiple links are possible
default_path_found = {} default_path_found = {}
for path in category_list: for path in category_list:
if path is not '': if path != '':
if base or len(base_category_list) > 1: if base or len(base_category_list) > 1:
# Only keep path which are member of base_category_list # Only keep path which are member of base_category_list
if self.getBaseCategoryId(path) in base_category_list: if self.getBaseCategoryId(path) in base_category_list:
if path not in default_new_category_list or default_path_found.has_key(path): if path not in default_new_category_list or default_path_found.has_key(path):
default_path_found[path] = 1 default_path_found[path] = 1
new_category_list += [path] new_category_list.append(path)
else: else:
new_path = base_category_list[0] + '/' + path new_path = '/'.join((base_category_list[0], path))
if new_path not in default_new_category_list: if new_path not in default_new_category_list:
new_category_list += [new_path] new_category_list.append(new_path)
#LOG("set Category",0,str(new_category_list)) #LOG("set Category",0,str(new_category_list))
#LOG("set Category",0,str(default_new_category_list)) #LOG("set Category",0,str(default_new_category_list))
self._setCategoryList(context, tuple(default_new_category_list + new_category_list)) self._setCategoryList(context, tuple(default_new_category_list + new_category_list))
......
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