Commit 5261391e authored by Julien Muchembled's avatar Julien Muchembled

DomainTool: small optimization of generateMultivaluedMappedValue

parent 5184f5ea
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
# #
############################################################################## ##############################################################################
from collections import defaultdict
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.ERP5Type.Globals import InitializeClass, DTMLFile from Products.ERP5Type.Globals import InitializeClass, DTMLFile
from Products.ERP5Type import Permissions from Products.ERP5Type import Permissions
...@@ -332,43 +333,28 @@ class DomainTool(BaseTool): ...@@ -332,43 +333,28 @@ class DomainTool(BaseTool):
# First get the list of predicates # First get the list of predicates
if predicate_list is None: if predicate_list is None:
predicate_list = self.searchPredicateList(context, test=test, **kw) predicate_list = self.searchPredicateList(context, test=test, **kw)
if len(predicate_list)==0: if predicate_list:
# No predicate, return None
mapped_value = None
else:
# Generate tempDeliveryCell
from Products.ERP5Type.Document import newTempSupplyCell from Products.ERP5Type.Document import newTempSupplyCell
mapped_value = newTempSupplyCell(self.getPortalObject(), mapped_value_property_dict = defaultdict(list)
'new_mapped_value') explanation_dict = defaultdict(dict)
mapped_value_property_dict = {}
processed_dict = {}
explanation_dict = {}
# Look for each property the first predicate with unique criterion # Look for each property the first predicate with unique criterion
# categories which defines the property # categories which defines the property
for predicate in predicate_list: for predicate in predicate_list:
predicate_category_list = \ full_prop_dict = explanation_dict[
tuple(predicate.getMembershipCriterionCategoryList()) tuple(predicate.getMembershipCriterionCategoryList())]
for mapped_value_property in predicate.getMappedValuePropertyList(): for mapped_value_property in predicate.getMappedValuePropertyList():
prop_list = processed_dict.setdefault(predicate_category_list, []) if mapped_value_property in full_prop_dict:
full_prop_dict = explanation_dict.setdefault(
predicate_category_list, {})
if mapped_value_property in prop_list:
# we already have one value for this (categories, property) # we already have one value for this (categories, property)
continue continue
value = predicate.getProperty(mapped_value_property) value = predicate.getProperty(mapped_value_property)
if value is not None: if value is not None:
prop_list.append(mapped_value_property)
full_prop_dict[mapped_value_property] = value full_prop_dict[mapped_value_property] = value
mv_prop_list = \ mapped_value_property_dict[mapped_value_property].append(value)
mapped_value_property_dict.setdefault(
mapped_value_property, [])
mv_prop_list.append(value)
if explanation_only: if explanation_only:
return explanation_dict return dict(explanation_dict)
# Update mapped value mapped_value = newTempSupplyCell(self.getPortalObject(),
mapped_value = mapped_value.asContext(**mapped_value_property_dict) 'new_mapped_value')
mapped_value.__dict__.update(mapped_value_property_dict)
return mapped_value return mapped_value
......
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