Commit a49997fc authored by Yoshinori Okuji's avatar Yoshinori Okuji

Clean up oldies.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@12644 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 67b83597
...@@ -47,6 +47,8 @@ import re ...@@ -47,6 +47,8 @@ import re
from zLOG import LOG, PROBLEM from zLOG import LOG, PROBLEM
_marker = object()
class CategoryError( Exception ): class CategoryError( Exception ):
pass pass
...@@ -186,7 +188,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -186,7 +188,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
if context is None: if context is None:
return self.objectValues() return self.objectValues()
else: else:
return map(lambda x:self[x], context._categories) # XXX Incompatible with ERP5Type per portal type categories return [self[x] for x in context._categories] # XXX Incompatible with ERP5Type per portal type categories
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getBaseCategoryValues') 'getBaseCategoryValues')
...@@ -269,7 +271,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -269,7 +271,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
if base_category is not None: if base_category is not None:
return base_category return base_category
try: try:
return relative_url.split('/')[0] return relative_url.split('/', 1)[0]
except KeyError : except KeyError :
return None return None
...@@ -303,7 +305,8 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -303,7 +305,8 @@ class CategoryTool( UniqueObject, Folder, Base ):
relative_url relative_url
""" """
uid_dict = {} uid_dict = {}
if type(relative_url) is type('a'): relative_url = (relative_url,) if isinstance(relative_url, str):
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)
...@@ -362,7 +365,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -362,7 +365,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
""" """
if base_category is None: if base_category is None:
base_category_list = self.getBaseCategoryList() base_category_list = self.getBaseCategoryList()
elif type(base_category) == type('a'): elif isinstance(base_category, str):
base_category_list = [base_category] base_category_list = [base_category]
else: else:
base_category_list = base_category base_category_list = base_category
...@@ -370,7 +373,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -370,7 +373,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
for base_category in base_category_list: for base_category in base_category_list:
category = self[base_category] category = self[base_category]
if category is not None: if category is not None:
result += category.getCategoryChildRelativeUrlList(base=base,recursive=recursive) result.extend(category.getCategoryChildRelativeUrlList(base=base,recursive=recursive))
return result return result
security.declareProtected(Permissions.AccessContentsInformation, 'getPathList') security.declareProtected(Permissions.AccessContentsInformation, 'getPathList')
...@@ -444,11 +447,11 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -444,11 +447,11 @@ class CategoryTool( UniqueObject, Folder, Base ):
for base_category in base_category_list: for base_category in base_category_list:
category = self[base_category] category = self[base_category]
if category is not None: if category is not None:
result += category.getCategoryChildItemList( result.extend(category.getCategoryChildItemList(
base=base, base=base,
recursive=recursive, recursive=recursive,
display_id=display_id, display_id=display_id,
**kw ) **kw ))
return result return result
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
...@@ -501,13 +504,13 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -501,13 +504,13 @@ class CategoryTool( UniqueObject, Folder, Base ):
# Convert a list of membership to path # Convert a list of membership to path
security.declareProtected(Permissions.View, 'asPathList') security.declareProtected(Permissions.View, 'asPathList')
def asPathList(self, base_category, category_list): def asPathList(self, base_category, category_list):
if type(category_list) == type('a'): if isinstance(category_list, str):
category_list = [category_list] category_list = [category_list]
if category_list == None: if category_list is None:
category_list = [] category_list = []
new_list = [] new_list = []
for v in category_list: for v in category_list:
new_list += ['%s/%s' % (base_category,v)] new_list.append('%s/%s' % (base_category, v))
return new_list return new_list
# Alias for compatibility # Alias for compatibility
...@@ -541,45 +544,45 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -541,45 +544,45 @@ class CategoryTool( UniqueObject, Folder, Base ):
# LOG('getCategoryMembershipList',0,str(spec)) # LOG('getCategoryMembershipList',0,str(spec))
# LOG('getCategoryMembershipList',0,str(base_category)) # LOG('getCategoryMembershipList',0,str(base_category))
membership = [] membership = []
if type(base_category) not in (type(()), type([])): if not isinstance(base_category, (tuple, list)):
category_list = [base_category] category_list = [base_category]
else: else:
category_list = base_category category_list = base_category
if type(spec) is not type([]) and type(spec) is not type(()): if not isinstance(spec, (tuple, list)):
spec = [spec] spec = [spec]
for path in self._getCategoryList(context): for path in self._getCategoryList(context):
# LOG('getCategoryMembershipList',0,str(path)) # LOG('getCategoryMembershipList',0,str(path))
my_base_category = path.split('/')[0] my_base_category = path.split('/', 1)[0]
for my_category in category_list: for my_category in category_list:
if type(my_category) is type('a'): if isinstance(my_category, str):
category = my_category category = my_category
else: else:
category = my_category.getRelativeUrl() category = my_category.getRelativeUrl()
if my_base_category == category: if my_base_category == category:
if spec is (): if spec is ():
if base: if base:
membership += [path] membership.append(path)
else: else:
membership += [path[len(category)+1:]] membership.append(path[len(category)+1:])
else: else:
try: try:
o = self.unrestrictedTraverse(path) o = self.unrestrictedTraverse(path)
# LOG('getCategoryMembershipList',0,str(o.portal_type)) # LOG('getCategoryMembershipList',0,str(o.portal_type))
if o.portal_type in spec: if o.portal_type in spec:
if base: if base:
membership += [path] membership.append(path)
else: else:
membership += [path[len(category)+1:]] membership.append(path[len(category)+1:])
except (KeyError, ): except KeyError:
LOG('WARNING: CategoriesTool',0, 'Unable to find object for path %s' % path) LOG('WARNING: CategoriesTool',0, 'Unable to find object for path %s' % path)
# We must include parent if specified explicitely # We must include parent if specified explicitely
if 'parent' in category_list: if 'parent' in category_list:
parent = context.aq_parent parent = context.aq_parent
if parent.portal_type in spec: if parent.portal_type in spec:
if base: if base:
membership += ['parent/' + parent.getRelativeUrl()] membership.append('parent/' + parent.getRelativeUrl())
else: else:
membership += [parent.getRelativeUrl()] membership.append(parent.getRelativeUrl())
return membership return membership
security.declareProtected( Permissions.AccessContentsInformation, 'setCategoryMembership' ) security.declareProtected( Permissions.AccessContentsInformation, 'setCategoryMembership' )
...@@ -603,7 +606,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -603,7 +606,7 @@ 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 type(portal_type) == type(''): if isinstance(portal_type, str):
portal_type = (portal_type,) portal_type = (portal_type,)
if spec is (): if spec is ():
spec = portal_type spec = portal_type
...@@ -611,16 +614,16 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -611,16 +614,16 @@ class CategoryTool( UniqueObject, Folder, Base ):
default_dict = {} default_dict = {}
self._cleanupCategories(context) self._cleanupCategories(context)
if type(category_list) is type('a'): if isinstance(category_list, str):
category_list = (category_list,) category_list = (category_list,)
elif category_list is None: elif category_list is None:
category_list = () category_list = ()
if type(base_category_list) is type('a'): if isinstance(base_category_list, str):
base_category_list = [base_category_list] base_category_list = [base_category_list]
new_category_list = [] new_category_list = []
for path in self._getCategoryList(context): for path in self._getCategoryList(context):
my_base_id = self.getBaseCategoryId(path) my_base_id = self.getBaseCategoryId(path)
if not my_base_id in base_category_list: if my_base_id not 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.append(path) new_category_list.append(path)
...@@ -664,7 +667,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -664,7 +667,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
default_path_found[path] = 1 default_path_found[path] = 1
new_category_list.append(path) new_category_list.append(path)
else: else:
new_path = '/'.join((base_category_list[0], path)) new_path = 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.append(new_path) new_category_list.append(new_path)
#LOG("set Category",0,str(new_category_list)) #LOG("set Category",0,str(new_category_list))
...@@ -689,7 +692,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -689,7 +692,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
""" """
self._cleanupCategories(context) self._cleanupCategories(context)
if type(default_category) is type([]) or type(default_category) is type(()): if isinstance(default_category, (tuple, list)):
default_category = default_category[0] default_category = default_category[0]
category_list = self.getCategoryMembershipList(context, base_category, category_list = self.getCategoryMembershipList(context, base_category,
spec=spec, filter=filter, portal_type=portal_type, base=base) spec=spec, filter=filter, portal_type=portal_type, base=base)
...@@ -702,7 +705,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -702,7 +705,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
if category == default_category: if category == default_category:
found_one = 1 found_one = 1
elif category != default_category or found_one: elif category != default_category or found_one:
new_category_list += [category] new_category_list.append(category)
self.setCategoryMembership(context, base_category, new_category_list, self.setCategoryMembership(context, base_category, new_category_list,
spec=spec, filter=filter, portal_type=portal_type, base=base, keep_default = 0) spec=spec, filter=filter, portal_type=portal_type, base=base, keep_default = 0)
...@@ -746,10 +749,10 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -746,10 +749,10 @@ class CategoryTool( UniqueObject, Folder, Base ):
# where_expression = self._buildQuery(spec, filter, kw) # where_expression = self._buildQuery(spec, filter, kw)
spec = kw.get('portal_type', ()) spec = kw.get('portal_type', ())
# Make sure spec is a list or tuple # Make sure spec is a list or tuple
if type(spec) is type('a'): if isinstance(spec, str):
spec = [spec] spec = [spec]
# Filter categories # Filter categories
if hasattr(aq_base(context), 'categories'): if getattr(aq_base(context), 'categories', _marker) is not _marker:
for category_url in self._getCategoryList(context): for category_url in self._getCategoryList(context):
try: try:
index = category_url.index('/') index = category_url.index('/')
...@@ -837,10 +840,10 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -837,10 +840,10 @@ class CategoryTool( UniqueObject, Folder, Base ):
portal_type = kw.get('portal_type', ()) portal_type = kw.get('portal_type', ())
if spec is (): spec = portal_type # This is bad XXX - JPS - spec is for meta_type, not for portal_type - be consistent ! if spec is (): spec = portal_type # This is bad XXX - JPS - spec is for meta_type, not for portal_type - be consistent !
if type(spec) is type('a'): if isinstance(spec, str):
spec = [spec] spec = [spec]
if type(acquired_portal_type) == type(''): if isinstance(acquired_portal_type, str):
acquired_portal_type = [acquired_portal_type] acquired_portal_type = [acquired_portal_type]
if acquired_object_dict is None: if acquired_object_dict is None:
...@@ -918,7 +921,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -918,7 +921,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
# We implement here special keywords # We implement here special keywords
if my_base_category == 'parent': if my_base_category == 'parent':
parent = context.aq_inner.aq_parent # aq_inner is required to make sure we use containment parent = context.aq_inner.aq_parent # aq_inner is required to make sure we use containment
if not hasattr(aq_base(parent), 'portal_type'): if getattr(aq_base(parent), 'portal_type', _marker) is _marker:
my_acquisition_object_list = [] my_acquisition_object_list = []
else: else:
#LOG("Parent Object List ",0,str(parent.getRelativeUrl())) #LOG("Parent Object List ",0,str(parent.getRelativeUrl()))
...@@ -1037,7 +1040,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -1037,7 +1040,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
extend = result.extend extend = result.extend
if base_category is None: if base_category is None:
base_category_list = context._categories # XXX incompatible with ERP5Type per portal categories base_category_list = context._categories # XXX incompatible with ERP5Type per portal categories
elif type(base_category) is type('a'): elif isinstance(base_category, str):
base_category_list = [base_category] base_category_list = [base_category]
else: else:
base_category_list = base_category base_category_list = base_category
...@@ -1142,14 +1145,14 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -1142,14 +1145,14 @@ class CategoryTool( UniqueObject, Folder, Base ):
security.declareProtected( Permissions.AccessContentsInformation, '_getCategoryList' ) security.declareProtected( Permissions.AccessContentsInformation, '_getCategoryList' )
def _getCategoryList(self, context): def _getCategoryList(self, context):
if hasattr(aq_base(context), 'categories'): if getattr(aq_base(context), 'categories', _marker) is not _marker:
if type(context.categories) == type((1,)): if isinstance(context.categories, tuple):
result = list(context.categories) result = list(context.categories)
elif type(context.categories) == type([]): elif isinstance(context.categories, list):
result = context.categories result = context.categories
else: else:
result = [] result = []
elif type(context) is type({}): elif isinstance(context, dict):
result = list(context.get('categories', [])) result = list(context.get('categories', []))
else: else:
result = [] result = []
...@@ -1192,9 +1195,9 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -1192,9 +1195,9 @@ class CategoryTool( UniqueObject, Folder, Base ):
requires_update = 0 requires_update = 0
categories = [] categories = []
append = categories.append append = categories.append
if hasattr(context, 'categories'): if getattr(context, 'categories', _marker) is not _marker:
for cat in self._getCategoryList(context): for cat in self._getCategoryList(context):
if type(cat) == type('a'): if isinstance(cat, str):
append(cat) append(cat)
else: else:
requires_update = 1 requires_update = 1
...@@ -1232,7 +1235,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -1232,7 +1235,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
new_category = self.updateRelatedCategory(category, new_category = self.updateRelatedCategory(category,
previous_category_url, previous_category_url,
new_category_url) new_category_url)
category_list += [new_category] category_list.append(new_category)
self._setCategoryList(o, category_list) self._setCategoryList(o, category_list)
if getattr(aq_base(o), if getattr(aq_base(o),
...@@ -1271,7 +1274,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -1271,7 +1274,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
strict_membership = kw.get('strict_membership', kw.get('strict', 0)) strict_membership = kw.get('strict_membership', kw.get('strict', 0))
portal_type = kw.get('portal_type') portal_type = kw.get('portal_type')
if type(portal_type) is type('a'): if isinstance(portal_type, str):
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
...@@ -1279,7 +1282,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -1279,7 +1282,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
if context.getPortalType() == 'Base Category': if context.getPortalType() == 'Base Category':
category_list = [context.getRelativeUrl()] category_list = [context.getRelativeUrl()]
else: else:
if type(base_category_list) is type('a'): if isinstance(base_category_list, str):
base_category_list = [base_category_list] base_category_list = [base_category_list]
elif base_category_list is () or base_category_list is None: elif base_category_list is () or base_category_list is None:
base_category_list = self.getBaseCategoryList() base_category_list = self.getBaseCategoryList()
...@@ -1329,14 +1332,14 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -1329,14 +1332,14 @@ class CategoryTool( UniqueObject, Folder, Base ):
List of lists List of lists
""" """
if type(category_list) == type('a'): if isinstance(category_list, str):
category_list = [category_list] category_list = [category_list]
sql_expr = [] sql_expr = []
for category in category_list: for category in category_list:
if category is None: if category is None:
pass pass
elif type(category) == type('a'): elif isinstance(category, str):
if category != '': if category:
category_uid = self.getCategoryUid(category) category_uid = self.getCategoryUid(category)
base_category_uid = self.getBaseCategoryUid(category) base_category_uid = self.getBaseCategoryUid(category)
expression = '' expression = ''
......
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