Commit 90efe13e authored by Romain Courteaud's avatar Romain Courteaud

Add tested_base_category_list parameter.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@5397 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 1fe5755d
......@@ -80,10 +80,14 @@ class Predicate(Folder):
__implements__ = ( Interface.Predicate )
security.declareProtected( Permissions.AccessContentsInformation, 'test' )
def test(self, context, **kw):
def test(self, context, tested_base_category_list=None, **kw):
"""
A Predicate can be tested on a given context.
Parameters can passed in order to ignore some conditions.
- tested_base_category_list: this is the list of category that we do
want to test. For example, we might want to test only the
destination or the source of a predicate.
"""
self = self.asPredicate()
result = 1
......@@ -120,7 +124,14 @@ class Predicate(Folder):
# (multimembership_criterion_base_category_list,
# membership_criterion_base_category_list,
# self.getMembershipCriterionCategoryList()))
for c in self.getMembershipCriterionCategoryList():
membership_criterion_category_list = \
self.getMembershipCriterionCategoryList()
if tested_base_category_list is not None:
membership_criterion_category_list = [x for x in \
membership_criterion_category_list if x.split('/')[0] in \
tested_base_category_list]
for c in membership_criterion_category_list:
bc = c.split('/')[0]
if (not bc in tested_base_category.keys()) and \
(bc in multimembership_criterion_base_category_list):
......@@ -137,6 +148,7 @@ class Predicate(Folder):
elif (bc in membership_criterion_base_category_list):
tested_base_category[bc] = tested_base_category[bc] or \
context.isMemberOf(c)
# LOG('predicate test', 0,
# '%s after single membership to %s' % \
# (tested_base_category[bc], c))
......@@ -432,4 +444,4 @@ class Predicate(Folder):
"""
Returns a list of documents matching the predicate
"""
pass
\ No newline at end of file
pass
......@@ -55,8 +55,9 @@ class DomainTool(BaseTool):
# (some users are not able to see resource's price)
security.declarePublic('searchPredicateList')
def searchPredicateList(self, context, test=1, sort_method=None,
ignored_category_list=None, filter_method=None,
acquired=1, **kw):
ignored_category_list=None,
tested_base_category_list=None,
filter_method=None, acquired=1, **kw):
"""
Search all predicates which corresponds to this particular
context.
......@@ -69,6 +70,10 @@ class DomainTool(BaseTool):
not want to test. For example, we might want to not test the
destination or the source of a predicate.
- tested_base_category_list: this is the list of category that we do
want to test. For example, we might want to test only the
destination or the source of a predicate.
- the acquired parameter allows to define if we want to use
acquisition for categories. By default we want.
"""
......@@ -127,23 +132,32 @@ class DomainTool(BaseTool):
checked_column_list.append('%s_range_max' % property)
# Add predicate.uid for automatic join
sql_kw['predicate.uid'] = '!=0'
where_expression = ' AND '.join(expression_list)
where_expression = ' AND \n'.join(expression_list)
# Add category selection
if acquired:
category_list = context.getAcquiredCategoryList()
else:
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 = '(%s) AND (%s)' % \
(where_expression,category_expression)
if tested_base_category_list is None:
if acquired:
category_list = context.getAcquiredCategoryList()
else:
category_list = context.getCategoryList()
else:
where_expression = category_expression
category_list = []
for tested_base_category in tested_base_category_list:
category_list.extend(
context.getCategoryMembershipList(tested_base_category, base=1))
if tested_base_category_list != []:
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 = '(%s) AND \n(%s)' % \
(where_expression,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'
......@@ -157,7 +171,9 @@ class DomainTool(BaseTool):
# LOG('searchPredicateList, result_list before test', 0,
# [x.getObject() for x in sql_result_list])
for predicate in [x.getObject() for x in sql_result_list]:
if test==0 or predicate.test(context):
if test==0 or predicate.test(
context,
tested_base_category_list=tested_base_category_list):
result_list.append(predicate)
# LOG('searchPredicateList, result_list before sort', 0, result_list)
if filter_method is not None:
......
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