def generateMultivaluedMappedValue(self, context, test=1, predicate_list=None, explanation_only=0, **kw): """ We will generate a mapped value with the list of all predicates found. Let's say we have 3 predicates (in the order we want) like this: Predicate 1 [ base_price1, , , , , , ] Predicate 2 [ base_price2, additional_price2 , , , , , ] Predicate 3 [ base_price3, additional_price3 , , , , , ] Our generated MappedValue will take all values for each property and put them in lists, unless predicates define the same list of criterion categories """ # First get the list of predicates if predicate_list is None: predicate_list = self.searchPredicateList(context, test=test, **kw) if len(predicate_list) == 0: # No predicate, return None mapped_value = None else: # Generate tempDeliveryCell from Products.ERP5Type.Document import newTempSupplyCell mapped_value = newTempSupplyCell(self.getPortalObject(), 'new_mapped_value') mapped_value_property_dict = {} processed_dict = {} explanation_dict = {} # Look for each property the first predicate with unique criterion # categories which defines the property for predicate in predicate_list: predicate_category_list = \ tuple(predicate.getMembershipCriterionCategoryList()) for mapped_value_property in predicate.getMappedValuePropertyList( ): prop_list = processed_dict.setdefault( predicate_category_list, []) 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) continue value = predicate.getProperty(mapped_value_property) if value is not None: prop_list.append(mapped_value_property) full_prop_dict[mapped_value_property] = value mv_prop_list = \ mapped_value_property_dict.setdefault( mapped_value_property, []) mv_prop_list.append(value) if explanation_only: return explanation_dict # Update mapped value mapped_value = mapped_value.asContext(**mapped_value_property_dict) return mapped_value
def generateMultivaluedMappedValue(self, context, test=1, predicate_list=None, explanation_only=0, **kw): """ We will generate a mapped value with the list of all predicates found. Let's say we have 3 predicates (in the order we want) like this: Predicate 1 [ base_price1, , , , , , ] Predicate 2 [ base_price2, additional_price2 , , , , , ] Predicate 3 [ base_price3, additional_price3 , , , , , ] Our generated MappedValue will take all values for each property and put them in lists, unless predicates define the same list of criterion categories """ # First get the list of predicates if predicate_list is None: predicate_list = self.searchPredicateList(context, test=test, **kw) if len(predicate_list)==0: # No predicate, return None mapped_value = None else: # Generate tempDeliveryCell from Products.ERP5Type.Document import newTempSupplyCell mapped_value = newTempSupplyCell(self.getPortalObject(), 'new_mapped_value') mapped_value_property_dict = {} processed_dict = {} explanation_dict = {} # Look for each property the first predicate with unique criterion # categories which defines the property for predicate in predicate_list: predicate_category_list = \ tuple(predicate.getMembershipCriterionCategoryList()) for mapped_value_property in predicate.getMappedValuePropertyList(): prop_list = processed_dict.setdefault(predicate_category_list, []) 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) continue value = predicate.getProperty(mapped_value_property) if value is not None: prop_list.append(mapped_value_property) full_prop_dict[mapped_value_property] = value mv_prop_list = \ mapped_value_property_dict.setdefault( mapped_value_property, []) mv_prop_list.append(value) if explanation_only: return explanation_dict # Update mapped value mapped_value = mapped_value.asContext(**mapped_value_property_dict) return mapped_value
def generateMappedValue(self, context, test=1, predicate_list=None, **kw): """ We will generate a mapped value with the list of all predicates found. Let's say we have 3 predicates (in the order we want) like this: Predicate 1 [ base_price1, , , , , , ] Predicate 2 [ base_price2, quantity2 , , , , , ] Predicate 3 [ base_price3, quantity3 , , , , , ] Our generated MappedValue will have the base_price of the predicate1, and the quantity of the Predicate2, because Predicate 1 is the first one which defines a base_price and the Predicate2 is the first one wich defines a quantity. """ # First get the list of predicates if predicate_list is None: predicate_list = self.searchPredicateList(context, test=test, **kw) if len(predicate_list) == 0: # No predicate, return None mapped_value = None else: # Generate tempDeliveryCell from Products.ERP5Type.Document import newTempSupplyCell mapped_value = newTempSupplyCell(self.getPortalObject(), 'new_mapped_value') mapped_value_property_dict = {} # Look for each property the first predicate which defines the # property for predicate in predicate_list: getMappedValuePropertyList = getattr( predicate, 'getMappedValuePropertyList', None) # searchPredicateList returns a list of any kind of predicate, which # includes predicates not containing any mapped value (for exemple, # domains). In such case, it has no meaning to handle them here. # A better way would be to tell catalog not to provide us with those # extra object, but there is no simple way (many portal types inherit # from MappedValue defining the accessor). # Feel free to improve. if getMappedValuePropertyList is not None: for mapped_value_property in predicate.getMappedValuePropertyList( ): if not mapped_value_property_dict.has_key( mapped_value_property): value = predicate.getProperty( mapped_value_property) if value is not None: mapped_value_property_dict[ mapped_value_property] = value # Update mapped value mapped_value.edit(**mapped_value_property_dict) return mapped_value
def generateMultivaluedMappedValue(self, context, test=1, predicate_list=None, explanation_only=0, **kw): """ We will generate a mapped value with the list of all predicates found. Let's say we have 3 predicates (in the order we want) like this: Predicate 1 [ base_price1, , , , , , ] Predicate 2 [ base_price2, additional_price2 , , , , , ] Predicate 3 [ base_price3, additional_price3 , , , , , ] Our generated MappedValue will take all values for each property and put them in lists, unless predicates define the same list of criterion categories """ # First get the list of predicates if predicate_list is None: predicate_list = self.searchPredicateList(context, test=test, **kw) if predicate_list: from Products.ERP5Type.Document import newTempSupplyCell mapped_value_property_dict = defaultdict(list) explanation_dict = defaultdict(dict) # Look for each property the first predicate with unique criterion # categories which defines the property for predicate in predicate_list: full_prop_dict = explanation_dict[tuple( predicate.getMembershipCriterionCategoryList())] for mapped_value_property in predicate.getMappedValuePropertyList( ): if mapped_value_property in full_prop_dict: # we already have one value for this (categories, property) continue value = predicate.getProperty(mapped_value_property) if value is not None: full_prop_dict[mapped_value_property] = value mapped_value_property_dict[ mapped_value_property].append(value) if explanation_only: return dict(explanation_dict) mapped_value = newTempSupplyCell(self.getPortalObject(), 'multivalued_mapped_value') mapped_value._setMappedValuePropertyList( mapped_value_property_dict.keys()) mapped_value.__dict__.update(mapped_value_property_dict) return mapped_value
def generateMappedValue(self, context, test=1, predicate_list=None, **kw): """ We will generate a mapped value with the list of all predicates found. Let's say we have 3 predicates (in the order we want) like this: Predicate 1 [ base_price1, , , , , , ] Predicate 2 [ base_price2, quantity2 , , , , , ] Predicate 3 [ base_price3, quantity3 , , , , , ] Our generated MappedValue will have the base_price of the predicate1, and the quantity of the Predicate2, because Predicate 1 is the first one which defines a base_price and the Predicate2 is the first one wich defines a quantity. """ # First get the list of predicates if predicate_list is None: predicate_list = self.searchPredicateList(context, test=test, **kw) if len(predicate_list)==0: # No predicate, return None mapped_value = None else: # Generate tempDeliveryCell from Products.ERP5Type.Document import newTempSupplyCell mapped_value = newTempSupplyCell(self.getPortalObject(), 'new_mapped_value') mapped_value_property_dict = {} # Look for each property the first predicate which defines the # property for predicate in predicate_list: getMappedValuePropertyList = getattr(predicate, 'getMappedValuePropertyList', None) # searchPredicateList returns a list of any kind of predicate, which # includes predicates not containing any mapped value (for exemple, # domains). In such case, it has no meaning to handle them here. # A better way would be to tell catalog not to provide us with those # extra object, but there is no simple way (many portal types inherit # from MappedValue defining the accessor). # Feel free to improve. if getMappedValuePropertyList is not None: for mapped_value_property in predicate.getMappedValuePropertyList(): if not mapped_value_property_dict.has_key(mapped_value_property): value = predicate.getProperty(mapped_value_property) if value is not None: mapped_value_property_dict[mapped_value_property] = value # Update mapped value mapped_value.edit(**mapped_value_property_dict) return mapped_value
def generateMultivaluedMappedValue(self, context, test=1, predicate_list=None, explanation_only=0, **kw): """ We will generate a mapped value with the list of all predicates found. Let's say we have 3 predicates (in the order we want) like this: Predicate 1 [ base_price1, , , , , , ] Predicate 2 [ base_price2, additional_price2 , , , , , ] Predicate 3 [ base_price3, additional_price3 , , , , , ] Our generated MappedValue will take all values for each property and put them in lists, unless predicates define the same list of criterion categories """ # First get the list of predicates if predicate_list is None: predicate_list = self.searchPredicateList(context, test=test, **kw) if predicate_list: from Products.ERP5Type.Document import newTempSupplyCell mapped_value_property_dict = defaultdict(list) explanation_dict = defaultdict(dict) # Look for each property the first predicate with unique criterion # categories which defines the property for predicate in predicate_list: full_prop_dict = explanation_dict[ tuple(predicate.getMembershipCriterionCategoryList())] for mapped_value_property in predicate.getMappedValuePropertyList(): if mapped_value_property in full_prop_dict: # we already have one value for this (categories, property) continue value = predicate.getProperty(mapped_value_property) if value is not None: full_prop_dict[mapped_value_property] = value mapped_value_property_dict[mapped_value_property].append(value) if explanation_only: return dict(explanation_dict) mapped_value = newTempSupplyCell(self.getPortalObject(), 'multivalued_mapped_value') mapped_value._setMappedValuePropertyList( mapped_value_property_dict.keys()) mapped_value.__dict__.update(mapped_value_property_dict) return mapped_value