Commit b49bed59 authored by Sebastien Robin's avatar Sebastien Robin

added method searchPredicateList


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@2792 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 61ad02f9
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
# #
# Copyright (c) 2002 Nexedi SARL and Contributors. All Rights Reserved. # Copyright (c) 2002 Nexedi SARL and Contributors. All Rights Reserved.
# Jean-Paul Smets-Solanes <jp@nexedi.com> # Jean-Paul Smets-Solanes <jp@nexedi.com>
# Sebastien Robin <seb@nexedi.com>
# #
# WARNING: This program as such is intended to be used by professional # WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential # programmers who take the whole responsability of assessing all potential
...@@ -35,6 +36,7 @@ from Products.ERP5Type import Permissions ...@@ -35,6 +36,7 @@ from Products.ERP5Type import Permissions
from Products.ERP5Type import _dtmldir from Products.ERP5Type import _dtmldir
from Products.ERP5Type.Tool.BaseTool import BaseTool from Products.ERP5Type.Tool.BaseTool import BaseTool
from Products.ERP5Type.Document.Folder import Folder from Products.ERP5Type.Document.Folder import Folder
from zLOG import LOG
class DomainTool(BaseTool): class DomainTool(BaseTool):
""" """
...@@ -56,4 +58,81 @@ class DomainTool(BaseTool): ...@@ -56,4 +58,81 @@ class DomainTool(BaseTool):
security.declareProtected( Permissions.ManagePortal, 'manage_overview' ) security.declareProtected( Permissions.ManagePortal, 'manage_overview' )
manage_overview = DTMLFile( 'explainDomainTool', _dtmldir ) manage_overview = DTMLFile( 'explainDomainTool', _dtmldir )
security.declarePublic('searchPredicateList')
def searchPredicateList(self,context,test=1,**kw):
"""
Search all predicates wich corresponds to this particular context.
"""
portal_catalog = context.portal_catalog
portal_categories = context.portal_categories
column_list = []
expression_list = []
checked_column_list = []
sql_kw = {}
for column in portal_catalog.getColumnIds():
if column.startswith('predicate.'):
column_list.append(column.split('.')[1])
for column in column_list:
if column in checked_column_list:
continue
range_property = 0
if column.endswith('_min') or column.startswith('_max'):
range_property = 1
property = column[-len('_min')]
if '%s_min' % column in column_list:
range_property = 1
property = column
if range_property:
# We have to check a range property
base_name = 'predicate.%s' % property
value = context.getProperty(property)
if value is None:
expression_list.append('%s is NULL AND %s_min is NULL AND %s_max is NULL' % ((base_name,)*3))
else:
expression = '%s is NULL AND %s_min is NULL AND %s_max is NULL ' % ((base_name,)*3)
expression += 'OR %s = %s ' % (base_name,value)
expression += 'OR %s_min <= %s AND %s_max is NULL ' % (base_name,value,base_name)
expression += 'OR %s_min is NULL AND %s_max > %s ' % (base_name,base_name,value)
expression += 'OR %s_min <= %s AND %s_max > %s ' % (base_name,value,base_name,value)
expression_list.append(expression)
checked_column_list.append('%s' % property)
checked_column_list.append('%s_min' % property)
checked_column_list.append('%s_max' % property)
# Add predicate.uid for automatic join
sql_kw['predicate.uid'] = '!=0'
where_expression = ' OR '.join(expression_list)
# Add category selection
category_list = context.getCategoryList()
if len(category_list)==0:
category_list = ['NULL']
category_expression = portal_categories.buildSQLSelector(category_list,query_table='predicate_category')
if len(where_expression)>0:
where_expression += ' AND (%s)' % category_expression
else:
where_expression = category_expression
sql_kw['where_expression'] = where_expression
# Add predicate_category.uid for automatic join
sql_kw['predicate_category.uid'] = '!=0'
kw.update(sql_kw)
sql_result_list = portal_catalog.searchResults(**kw)
result_list = []
for predicate in [x.getObject() for x in sql_result_list]:
if test or predicate.test(context):
result_list.append(predicate)
return result_list
security.declarePublic('generateMappedValue')
def generateMappedValue(self,context,test=1,**kw):
"""
"""
pass
InitializeClass(DomainTool) InitializeClass(DomainTool)
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