Commit 496b7f84 authored by Yoshinori Okuji's avatar Yoshinori Okuji

Specify a default value to base_category_list in getRelatedValueList.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@1495 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent d459963e
...@@ -685,6 +685,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -685,6 +685,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
if spec is (): spec = portal_type if spec is (): spec = portal_type
# We must treat parent in a different way # We must treat parent in a different way
#LOG('getSingleCategoryMembershipList', 0, 'base_category = %s, spec = %s, base = %s, context = %s, context.aq_parent = %s' % (repr(base_category), repr(spec), repr(base), repr(context), repr(context.aq_parent)))
if base_category == 'parent': if base_category == 'parent':
parent = context.aq_parent # aq_inner ? parent = context.aq_parent # aq_inner ?
if parent.portal_type in spec: if parent.portal_type in spec:
...@@ -692,8 +693,9 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -692,8 +693,9 @@ class CategoryTool( UniqueObject, Folder, Base ):
return ['parent/' + parent.getRelativeUrl()] return ['parent/' + parent.getRelativeUrl()]
else: else:
return [parent.getRelativeUrl()] return [parent.getRelativeUrl()]
return [] #LOG('getSingleCategoryMembershipList', 0, 'not in spec: parent.portal_type = %s, spec = %s' % (repr(parent.portal_type), repr(spec)))
return []
result = [] result = []
# 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)
...@@ -768,7 +770,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -768,7 +770,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
if type(spec) is type('a'): if type(spec) is type('a'):
spec = [spec] spec = [spec]
if acquired_object_dict is None: if acquired_object_dict is None:
acquired_object_dict = {} # Initial call may include filter, etc. - do not keep acquired_object_dict = {} # Initial call may include filter, etc. - do not keep
else: else:
...@@ -781,13 +783,13 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -781,13 +783,13 @@ class CategoryTool( UniqueObject, Folder, Base ):
return [] return []
else: else:
type_dict[()] = 1 type_dict[()] = 1
else: else:
for pt in spec: for pt in spec:
if pt in type_dict: if pt in type_dict:
return [] return []
else: else:
type_dict[pt] = 1 type_dict[pt] = 1
else: else:
type_dict = {} type_dict = {}
if spec is (): if spec is ():
type_dict[()] = 1 type_dict[()] = 1
...@@ -796,11 +798,13 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -796,11 +798,13 @@ class CategoryTool( UniqueObject, Folder, Base ):
type_dict[pt] = 1 type_dict[pt] = 1
acquired_object_dict = deepcopy(acquired_object_dict) acquired_object_dict = deepcopy(acquired_object_dict)
acquired_object_dict[context_base_key] = type_dict acquired_object_dict[context_base_key] = type_dict
result = self.getSingleCategoryMembershipList( context, base_category, base=base, result = self.getSingleCategoryMembershipList( context, base_category, base=base,
spec=spec, filter=filter, **kw ) spec=spec, filter=filter, **kw )
base_category_value = self.getCategoryValue(base_category) base_category_value = self.getCategoryValue(base_category)
# LOG("base_category_value",0,str(base_category_value))
# LOG("result",0,str(result))
if base_category_value is not None: if base_category_value 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 base_category_value.getAcquisitionMaskValue() and \ if base_category_value.getAcquisitionMaskValue() and \
...@@ -815,7 +819,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -815,7 +819,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
#my_acquisition_object_path = my_acquisition_object.getPhysicalPath() #my_acquisition_object_path = my_acquisition_object.getPhysicalPath()
#if my_acquisition_object_path in acquired_object_dict: #if my_acquisition_object_path in acquired_object_dict:
# continue # continue
#acquired_object_dict[my_acquisition_object_path] = 1 #acquired_object_dict[my_acquisition_object_path] = 1
if my_acquisition_object.portal_type in base_category_value.getAcquisitionPortalTypeList(): if my_acquisition_object.portal_type in base_category_value.getAcquisitionPortalTypeList():
new_result = self.getSingleCategoryAcquiredMembershipList(my_acquisition_object, new_result = self.getSingleCategoryAcquiredMembershipList(my_acquisition_object,
base_category, spec=spec, filter=filter, portal_type=portal_type, base=base, acquired_object_dict=acquired_object_dict) base_category, spec=spec, filter=filter, portal_type=portal_type, base=base, acquired_object_dict=acquired_object_dict)
...@@ -849,7 +853,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -849,7 +853,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
#my_acquisition_object_path = parent.getPhysicalPath() #my_acquisition_object_path = parent.getPhysicalPath()
#if my_acquisition_object_path in acquired_object_dict: #if my_acquisition_object_path in acquired_object_dict:
if acquisition_pt is () or parent.portal_type in acquisition_pt: if acquisition_pt is () or parent.portal_type in acquisition_pt:
my_acquisition_object_list = [parent] my_acquisition_object_list = [parent]
else: else:
my_acquisition_object_list = [] my_acquisition_object_list = []
#else: #else:
...@@ -858,7 +862,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -858,7 +862,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
#LOG('getAcquiredCategoryMembershipList', 0, 'my_acquisition_object = %s, acquired_object_dict = %s' % (str(context), str(acquired_object_dict))) #LOG('getAcquiredCategoryMembershipList', 0, 'my_acquisition_object = %s, acquired_object_dict = %s' % (str(context), str(acquired_object_dict)))
my_acquisition_list = self.getSingleCategoryAcquiredMembershipList(context, my_acquisition_list = self.getSingleCategoryAcquiredMembershipList(context,
my_base_category, my_base_category,
portal_type=tuple(base_category_value.getAcquisitionPortalTypeList(())), portal_type=tuple(base_category_value.getAcquisitionPortalTypeList(())),
acquired_object_dict=acquired_object_dict) acquired_object_dict=acquired_object_dict)
my_acquisition_object_list = [] my_acquisition_object_list = []
for c in my_acquisition_list: for c in my_acquisition_list:
...@@ -896,7 +900,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -896,7 +900,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
# If acquisition appends, then we must append to the result # If acquisition appends, then we must append to the result
result += new_result result += new_result
elif len(new_result) > 0: elif len(new_result) > 0:
LOG("new_result ",0,str(new_result)) #LOG("new_result ",0,str(new_result))
if (base_category_value.acquisition_copy_value and len(original_result) == 0) \ if (base_category_value.acquisition_copy_value and len(original_result) == 0) \
or base_category_value.acquisition_sync_value: or base_category_value.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
...@@ -937,11 +941,11 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -937,11 +941,11 @@ class CategoryTool( UniqueObject, Folder, Base ):
base_category_list = [base_category] base_category_list = [base_category]
else: else:
base_category_list = base_category base_category_list = base_category
LOG('CT.getAcquiredCategoryMembershipList result',0,result) #LOG('CT.getAcquiredCategoryMembershipList result',0,result)
for base_category in base_category_list: for base_category in base_category_list:
result += self.getSingleCategoryAcquiredMembershipList(context, base_category, base=base, result += self.getSingleCategoryAcquiredMembershipList(context, base_category, base=base,
spec=spec, filter=filter, acquired_object_dict=acquired_object_dict, **kw ) spec=spec, filter=filter, acquired_object_dict=acquired_object_dict, **kw )
LOG('CT.getAcquiredCategoryMembershipList new result',0,result) #LOG('CT.getAcquiredCategoryMembershipList new result',0,result)
return result return result
security.declareProtected( Permissions.AccessContentsInformation, 'isMemberOf' ) security.declareProtected( Permissions.AccessContentsInformation, 'isMemberOf' )
...@@ -1081,8 +1085,8 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -1081,8 +1085,8 @@ class CategoryTool( UniqueObject, Folder, Base ):
previous_category_url,'\g<start>/%s/\g<stop>' % new_category_url,category) previous_category_url,'\g<start>/%s/\g<stop>' % new_category_url,category)
new_category = re.sub('(?P<start>.*)/%s$' % new_category = re.sub('(?P<start>.*)/%s$' %
previous_category_url,'\g<start>/%s' % new_category_url, new_category) previous_category_url,'\g<start>/%s' % new_category_url, new_category)
return new_category return new_category
def updateRelatedContent(self, context, previous_category_url, new_category_url): def updateRelatedContent(self, context, previous_category_url, new_category_url):
""" """
TODO: make this method resist to very large updates (ie. long transaction) TODO: make this method resist to very large updates (ie. long transaction)
...@@ -1114,8 +1118,8 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -1114,8 +1118,8 @@ class CategoryTool( UniqueObject, Folder, Base ):
new_category_url,'\g<start>/%s' % previous_category_url, new_o_category_url) new_category_url,'\g<start>/%s' % previous_category_url, new_o_category_url)
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.AccessContentsInformation, 'getRelatedValueList' )
def getRelatedValueList(self, context, base_category_list, def getRelatedValueList(self, context, base_category_list=None,
spec=(), filter=None, base=1, **kw): spec=(), filter=None, base=1, **kw):
#LOG('getRelatedValueList',0,'base_category_list: %s, filter: %s, kw: %s' % #LOG('getRelatedValueList',0,'base_category_list: %s, filter: %s, kw: %s' %
# (str(base_category_list),str(filter),str(kw))) # (str(base_category_list),str(filter),str(kw)))
......
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