Commit 23e6cab8 authored by Jean-Paul Smets's avatar Jean-Paul Smets

propagate acquisition for acquired_membership


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@812 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 7319c665
......@@ -746,16 +746,26 @@ class CategoryTool( UniqueObject, Folder, Base ):
#LOG("Get Acquired Category ",0,str((base_category, context)))
# XXX We must use filters in the future
# query = self._buildQuery(spec, filter, kw)
if acquired_object_dict is None:
acquired_object_dict = {}
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 type(spec) is type('a'):
spec = [spec]
if acquired_object_dict is None:
acquired_object_dict = {}
else:
context_key = (context.getPhysicalPath(), base_category, portal_type) # Prevents recursion in category acquisition
if context_key in acquired_object_dict:
# Stop recursion if this object if already used
return []
else:
acquired_object_dict[context_key] = 1
result = self.getSingleCategoryMembershipList( context, base_category, base=base,
spec=spec, filter=filter, **kw )
base_category_value = self.getCategoryValue(base_category)
if base_category_value is not None:
# If we do not mask or append, return now if not empty
......@@ -767,10 +777,11 @@ class CategoryTool( UniqueObject, Folder, Base ):
# First we look at local ids
for object_id in base_category_value.getAcquisitionObjectIdList():
my_acquisition_object = context.get(object_id)
if my_acquisition_object in acquired_object_dict:
continue
acquired_object_dict[my_acquisition_object] = 1
if my_acquisition_object is not None:
#my_acquisition_object_path = my_acquisition_object.getPhysicalPath()
#if my_acquisition_object_path in acquired_object_dict:
# continue
#acquired_object_dict[my_acquisition_object_path] = 1
if spec is () or my_acquisition_object.portal_type in base_category_value.getAcquisitionPortalTypeList():
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)
......@@ -797,13 +808,27 @@ class CategoryTool( UniqueObject, Folder, Base ):
#LOG("Parent Object List ",0,str(parent.getRelativeUrl()))
#LOG("Parent Object List ",0,str(parent.portal_type))
#LOG("Parent Object List ",0,str(acquisition_pt))
#my_acquisition_object_path = parent.getPhysicalPath()
#if my_acquisition_object_path in acquired_object_dict:
if acquisition_pt is () or parent.portal_type in acquisition_pt:
my_acquisition_object_list = [parent]
else:
my_acquisition_object_list = []
#else:
# my_acquisition_object_list = []
else:
my_acquisition_object_list = context.getValueList(my_base_category,
portal_type=tuple(base_category_value.getAcquisitionPortalTypeList(())))
#LOG('getAcquiredCategoryMembershipList', 0, 'my_acquisition_object = %s, acquired_object_dict = %s' % (str(context), str(acquired_object_dict)))
my_acquisition_list = self.getAcquiredCategoryMembershipList(context,
my_base_category,
portal_type=tuple(base_category_value.getAcquisitionPortalTypeList(())),
acquired_object_dict=acquired_object_dict)
my_acquisition_object_list = []
for c in my_acquisition_object_list:
o = self.resolveCategory(c)
if o is not None:
my_acquisition_object_list.append(o)
#my_acquisition_object_list = context.getValueList(my_base_category,
# portal_type=tuple(base_category_value.getAcquisitionPortalTypeList(())))
#LOG("Get Acquired PT",0,str(base_category.getAcquisitionPortalTypeList(())))
#LOG("Object List ",0,str(my_acquisition_object_list))
original_result = result
......@@ -814,10 +839,10 @@ class CategoryTool( UniqueObject, Folder, Base ):
#LOG('getSingleCategoryAcquiredMembershipList', 0, 'my_acquisition_object.__hash__ = %s' % str(my_acquisition_object.__hash__()))
#if my_acquisition_object is not None:
if my_acquisition_object is not None:
if hasattr(my_acquisition_object, '__hash__'):
if my_acquisition_object in acquired_object_dict:
continue
acquired_object_dict[my_acquisition_object] = 1
#my_acquisition_object_path = my_acquisition_object.getPhysicalPath()
#if my_acquisition_object_path in acquired_object_dict:
# continue
#acquired_object_dict[my_acquisition_object_path] = 1
if hasattr(my_acquisition_object, '_categories'):
# We should only consider objects which define that category
if base_category in my_acquisition_object._categories:
......@@ -855,7 +880,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
security.declareProtected( Permissions.AccessContentsInformation,
'getAcquiredCategoryMembershipList' )
def getAcquiredCategoryMembershipList(self, context, base_category = None, base=1,
spec=(), filter=None, **kw):
spec=(), filter=None, acquired_object_dict=None, **kw):
"""
Returns all acquired category values
"""
......@@ -869,7 +894,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
base_category_list = base_category
for base_category in base_category_list:
result += self.getSingleCategoryAcquiredMembershipList(context, base_category, base=base,
spec=spec, filter=filter, **kw )
spec=spec, filter=filter, acquired_object_dict=acquired_object_dict, **kw )
return result
security.declareProtected( Permissions.AccessContentsInformation, 'isMemberOf' )
......
......@@ -197,7 +197,8 @@ class Base( CopyContainer, PortalContent, Base18, ActiveObject, ERP5PropertyMana
return getattr(self, storage_id)
# Retrieve the list of related objects
#LOG("Get Acquired Property portal_type",0,str(portal_type))
super_list = self._getValueList(base_category, portal_type=portal_type) # We only do a single jump
#super_list = self._getValueList(base_category, portal_type=portal_type) # We only do a single jump
super_list = self._getAcquiredValueList(base_category, portal_type=portal_type) # We only do a single jump
#LOG("Get Acquired Property super_list",0,str(super_list))
#LOG("Get Acquired Property accessor_id",0,str(accessor_id))
if len(super_list) > 0:
......@@ -281,7 +282,8 @@ class Base( CopyContainer, PortalContent, Base18, ActiveObject, ERP5PropertyMana
super = None
psuper = []
for cat in base_category:
super_list = self._getValueList(cat) # We only do a single jump - no acquisition
#super_list = self._getValueList(cat) # We only do a single jump - no acquisition
super_list = self._getAcquiredValueList(cat) # We only do a single jump - no acquisition
for super in super_list:
if super is not None:
# Performance should be increased
......@@ -706,7 +708,7 @@ class Base( CopyContainer, PortalContent, Base18, ActiveObject, ERP5PropertyMana
security.declareProtected( Permissions.View, '_getDefaultRelatedValue' )
def _getDefaultRelatedValue(self, id, spec=(), filter=None, portal_type=()):
value_list =self._getCategoryTool().getRelatedValueList(self, id, spec=spec, filter=filter, portal_type=portal_type)
value_list =self._getRelatedValueList(id, spec=spec, filter=filter, portal_type=portal_type)
try:
return value_list[0]
except:
......
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