Commit 44427f80 authored by Sebastien Robin's avatar Sebastien Robin

fixed logical error in the sql query of searchPredicateList


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@3065 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent afcf609b
...@@ -59,9 +59,19 @@ class DomainTool(BaseTool): ...@@ -59,9 +59,19 @@ class DomainTool(BaseTool):
manage_overview = DTMLFile( 'explainDomainTool', _dtmldir ) manage_overview = DTMLFile( 'explainDomainTool', _dtmldir )
security.declarePublic('searchPredicateList') security.declarePublic('searchPredicateList')
def searchPredicateList(self,context,test=1,sort_method=None,**kw): def searchPredicateList(self,context,test=1,sort_method=None,
ignored_category_list=None,**kw):
""" """
Search all predicates wich corresponds to this particular context. Search all predicates wich corresponds to this particular context.
- The sort_method parameter allows to give a method wich will be
used in order to sort the list of predicates founds. The most
important predicate is the first one in the list.
- ignored_category_list : this is the list of category that we do
not want to test. For example, we might want to not test the
destination or the source of a predicate.
""" """
portal_catalog = context.portal_catalog portal_catalog = context.portal_catalog
portal_categories = context.portal_categories portal_categories = context.portal_categories
...@@ -108,7 +118,7 @@ class DomainTool(BaseTool): ...@@ -108,7 +118,7 @@ class DomainTool(BaseTool):
category_list = ['NULL'] category_list = ['NULL']
category_expression = portal_categories.buildSQLSelector(category_list,query_table='predicate_category') category_expression = portal_categories.buildSQLSelector(category_list,query_table='predicate_category')
if len(where_expression)>0: if len(where_expression)>0:
where_expression += ' AND (%s)' % category_expression where_expression = '(%s) AND (%s)' % (where_expression,category_expression)
else: else:
where_expression = category_expression where_expression = category_expression
sql_kw['where_expression'] = where_expression sql_kw['where_expression'] = where_expression
...@@ -119,7 +129,7 @@ class DomainTool(BaseTool): ...@@ -119,7 +129,7 @@ class DomainTool(BaseTool):
sql_result_list = portal_catalog.searchResults(**kw) sql_result_list = portal_catalog.searchResults(**kw)
result_list = [] result_list = []
for predicate in [x.getObject() for x in sql_result_list]: for predicate in [x.getObject() for x in sql_result_list]:
if test or predicate.test(context): if test==0 or predicate.test(context):
result_list.append(predicate) result_list.append(predicate)
#LOG('searchPredicateList, result_list before sort',0,result_list) #LOG('searchPredicateList, result_list before sort',0,result_list)
if sort_method is not None: if sort_method is not None:
...@@ -128,7 +138,7 @@ class DomainTool(BaseTool): ...@@ -128,7 +138,7 @@ class DomainTool(BaseTool):
return result_list return result_list
security.declarePublic('generateMappedValue') security.declarePublic('generateMappedValue')
def generateMappedValue(self,context,test=1,**kw): def generateMappedValue(self,context,test=1,predicate_list=None,**kw):
""" """
We will generate a mapped value witht the list of all predicates founds. Let's say We will generate a mapped value witht the list of all predicates founds. Let's say
we have 3 predicates (in the order we want) like this: we have 3 predicates (in the order we want) like this:
...@@ -141,28 +151,24 @@ class DomainTool(BaseTool): ...@@ -141,28 +151,24 @@ class DomainTool(BaseTool):
Predicate2 is the first one wich defines a quantity Predicate2 is the first one wich defines a quantity
""" """
# First get the list of predicates # First get the list of predicates
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:
return None
#mapped_value = newTempBase(self.getPortalObject(),'new_mapped_value') #mapped_value = newTempBase(self.getPortalObject(),'new_mapped_value')
from Products.ERP5Type.Document import newTempDeliveryCell from Products.ERP5Type.Document import newTempDeliveryCell
mapped_value = newTempDeliveryCell(self.getPortalObject(),'new_mapped_value') mapped_value = newTempDeliveryCell(self.getPortalObject(),'new_mapped_value')
mapped_value_property_dict = {} mapped_value_property_dict = {}
#mapped_value = self
# Look for each property the first predicate wich defines the property # Look for each property the first predicate wich defines the property
#LOG('DomainTool.generateMappedValue predicate_list',0,[x.getPath() for x in predicate_list])
for predicate in predicate_list: for predicate in predicate_list:
#LOG('DomainTool.generateMappedValue predicate',0,predicate.getPath())
for mapped_value_property in predicate.getMappedValuePropertyList(): for mapped_value_property in predicate.getMappedValuePropertyList():
if not mapped_value_property_dict.has_key(mapped_value_property): if not mapped_value_property_dict.has_key(mapped_value_property):
value = predicate.getProperty(mapped_value_property) value = predicate.getProperty(mapped_value_property)
#LOG('DomainTool.generateMappedValue (property,value)',0,(mapped_value_property,value))
if value is not None: if value is not None:
mapped_value_property_dict[mapped_value_property] = value mapped_value_property_dict[mapped_value_property] = value
mapped_value = mapped_value.asContext(**mapped_value_property_dict) mapped_value = mapped_value.asContext(**mapped_value_property_dict)
#LOG('DomainTool.generateMappedValue mapped_value_property_dict',0,mapped_value_property_dict)
#LOG('DomainTool.generateMappedValue mapped_value.__dict__',0,mapped_value.__dict__)
#LOG('DomainTool.generateMappedValue mapped_value',0,mapped_value)
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