Commit e5edf944 authored by Yoshinori Okuji's avatar Yoshinori Okuji

Re-apply r37787 with even more simplification.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@39042 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent e7af42bd
...@@ -847,7 +847,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -847,7 +847,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
security.declareProtected( Permissions.AccessContentsInformation, security.declareProtected( Permissions.AccessContentsInformation,
'getSingleCategoryAcquiredMembershipList' ) 'getSingleCategoryAcquiredMembershipList' )
def getSingleCategoryAcquiredMembershipList(self, context, base_category, base=0, def getSingleCategoryAcquiredMembershipList(self, context, base_category, base=0,
spec=(), filter=None, acquired_object_dict = None, **kw ): spec=(), filter=None, _acquired_object_set=None, **kw ):
cache = getReadOnlyTransactionCache() cache = getReadOnlyTransactionCache()
if cache is not None: if cache is not None:
key = ('getSingleCategoryAcquiredMembershipList', context.getPhysicalPath(), base_category, base, spec, key = ('getSingleCategoryAcquiredMembershipList', context.getPhysicalPath(), base_category, base, spec,
...@@ -859,7 +859,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -859,7 +859,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
result = self._getSingleCategoryAcquiredMembershipList(context, base_category, base=base, result = self._getSingleCategoryAcquiredMembershipList(context, base_category, base=base,
spec=spec, filter=filter, spec=spec, filter=filter,
acquired_object_dict = acquired_object_dict, _acquired_object_set=_acquired_object_set,
**kw) **kw)
if cache is not None: if cache is not None:
cache[key] = result cache[key] = result
...@@ -892,8 +892,8 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -892,8 +892,8 @@ class CategoryTool( UniqueObject, Folder, Base ):
def _getSingleCategoryAcquiredMembershipList(self, context, base_category, def _getSingleCategoryAcquiredMembershipList(self, context, base_category,
base = 0, spec = (), filter = None, base = 0, spec = (), filter = None,
acquired_portal_type = (), acquired_portal_type = (),
acquired_object_dict = None,
checked_permission = None, checked_permission = None,
_acquired_object_set=None,
**kw ): **kw ):
""" """
Returns the acquired membership of the context for a single base category Returns the acquired membership of the context for a single base category
...@@ -911,9 +911,6 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -911,9 +911,6 @@ class CategoryTool( UniqueObject, Folder, Base ):
checked_permission -- a string which defined the permission checked_permission -- a string which defined the permission
to filter the object on to filter the object on
acquired_object_dict -- this is the list of object used by acquisition, so
we can check if we already have used this object
alt_base_category -- an alternative base category if the first one fails alt_base_category -- an alternative base category if the first one fails
acquisition_copy_value -- if set to 1, the looked up value will be copied acquisition_copy_value -- if set to 1, the looked up value will be copied
...@@ -924,6 +921,9 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -924,6 +921,9 @@ class CategoryTool( UniqueObject, Folder, Base ):
acquisition_sync_value -- if set to 1, keep self and looked up value in sync acquisition_sync_value -- if set to 1, keep self and looked up value in sync
_acquired_object_set is a special, internal parameter to deal with
recursive calls on the same object.
""" """
#LOG("Get Acquired Category ",0,str((base_category, context,))) #LOG("Get Acquired Category ",0,str((base_category, context,)))
#LOG("Get Acquired Category acquired_object_dict: ",0,str(acquired_object_dict)) #LOG("Get Acquired Category acquired_object_dict: ",0,str(acquired_object_dict))
...@@ -938,34 +938,15 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -938,34 +938,15 @@ class CategoryTool( UniqueObject, Folder, Base ):
if isinstance(acquired_portal_type, str): 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_set is None:
acquired_object_dict = {} # Initial call may include filter, etc. - do not keep _acquired_object_set = set()
else:
context_base_key = (tuple(context.getPhysicalPath()), base_category)
if context_base_key in acquired_object_dict:
acquired_object_dict = acquired_object_dict.copy()
type_set = acquired_object_dict[context_base_key].copy()
if spec is ():
if () in type_set:
return []
else: else:
type_set.add(()) uid = context.getUid()
else: key = (uid, base_category, tuple(spec))
for pt in spec: if key in _acquired_object_set:
if pt in type_set:
return [] return []
else: _acquired_object_set = _acquired_object_set.copy()
type_set.add(pt) _acquired_object_set.add(key)
acquired_object_dict[context_base_key] = type_set
else:
type_set = set()
if spec is ():
type_set.add(())
else:
for pt in spec:
type_set.add(pt)
acquired_object_dict = acquired_object_dict.copy()
acquired_object_dict[context_base_key] = type_set
result = self.getSingleCategoryMembershipList( context, base_category, base=base, result = self.getSingleCategoryMembershipList( context, base_category, base=base,
spec=spec, filter=filter, **kw ) # Not acquired because this is the first try spec=spec, filter=filter, **kw ) # Not acquired because this is the first try
...@@ -993,7 +974,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -993,7 +974,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
#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_set=_acquired_object_set)
else: else:
new_result = [] new_result = []
#if base_category_value.acquisition_mask_value: #if base_category_value.acquisition_mask_value:
...@@ -1034,7 +1015,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -1034,7 +1015,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
my_acquisition_list = self.getSingleCategoryAcquiredMembershipList(context, my_acquisition_list = self.getSingleCategoryAcquiredMembershipList(context,
my_base_category, my_base_category,
portal_type=tuple(acquisition_pt), portal_type=tuple(acquisition_pt),
acquired_object_dict=acquired_object_dict) _acquired_object_set=_acquired_object_set)
my_acquisition_object_list = [] my_acquisition_object_list = []
if my_acquisition_list: if my_acquisition_list:
resolveCategory = self.resolveCategory resolveCategory = self.resolveCategory
...@@ -1070,7 +1051,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -1070,7 +1051,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
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, base_category, spec=spec, filter=filter, portal_type=portal_type, base=base,
acquired_portal_type=acquired_portal_type, acquired_portal_type=acquired_portal_type,
acquired_object_dict=acquired_object_dict) _acquired_object_set=_acquired_object_set)
else: else:
#LOG("No recursive call ",0,str((spec, my_acquisition_object.portal_type))) #LOG("No recursive call ",0,str((spec, my_acquisition_object.portal_type)))
new_result = [] new_result = []
...@@ -1109,7 +1090,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -1109,7 +1090,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
for base_category in fallback_base_category_list: for base_category in fallback_base_category_list:
# First get the category list # First get the category list
category_list = getSingleCategoryAcquiredMembershipList( context, base_category, base=1, category_list = getSingleCategoryAcquiredMembershipList( context, base_category, base=1,
spec=spec, filter=filter, acquired_object_dict=acquired_object_dict, **kw ) spec=spec, filter=filter, _acquired_object_set=_acquired_object_set, **kw )
# Then convert it into value # Then convert it into value
category_value_list = [resolveCategory(x) for x in category_list] category_value_list = [resolveCategory(x) for x in category_list]
# Then build the alternate category # Then build the alternate category
...@@ -1139,7 +1120,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -1139,7 +1120,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
security.declareProtected( Permissions.AccessContentsInformation, security.declareProtected( Permissions.AccessContentsInformation,
'getAcquiredCategoryMembershipList' ) 'getAcquiredCategoryMembershipList' )
def getAcquiredCategoryMembershipList(self, context, base_category = None, base=1, def getAcquiredCategoryMembershipList(self, context, base_category = None, base=1,
spec=(), filter=None, acquired_object_dict=None, **kw): spec=(), filter=None, _acquired_object_set=None, **kw):
""" """
Returns all acquired category values Returns all acquired category values
""" """
...@@ -1156,7 +1137,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -1156,7 +1137,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
getSingleCategoryAcquiredMembershipList = self.getSingleCategoryAcquiredMembershipList getSingleCategoryAcquiredMembershipList = self.getSingleCategoryAcquiredMembershipList
for base_category in base_category_list: for base_category in base_category_list:
extend(getSingleCategoryAcquiredMembershipList(context, base_category, base=base, extend(getSingleCategoryAcquiredMembershipList(context, base_category, base=base,
spec=spec, filter=filter, acquired_object_dict=acquired_object_dict, **kw )) spec=spec, filter=filter, _acquired_object_set=_acquired_object_set, **kw ))
#LOG('CT.getAcquiredCategoryMembershipList new result',0,result) #LOG('CT.getAcquiredCategoryMembershipList new result',0,result)
return result return result
......
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