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): ...@@ -80,10 +80,14 @@ class Predicate(Folder):
__implements__ = ( Interface.Predicate ) __implements__ = ( Interface.Predicate )
security.declareProtected( Permissions.AccessContentsInformation, 'test' ) 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. A Predicate can be tested on a given context.
Parameters can passed in order to ignore some conditions. 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() self = self.asPredicate()
result = 1 result = 1
...@@ -120,7 +124,14 @@ class Predicate(Folder): ...@@ -120,7 +124,14 @@ class Predicate(Folder):
# (multimembership_criterion_base_category_list, # (multimembership_criterion_base_category_list,
# membership_criterion_base_category_list, # membership_criterion_base_category_list,
# self.getMembershipCriterionCategoryList())) # 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] bc = c.split('/')[0]
if (not bc in tested_base_category.keys()) and \ if (not bc in tested_base_category.keys()) and \
(bc in multimembership_criterion_base_category_list): (bc in multimembership_criterion_base_category_list):
...@@ -137,6 +148,7 @@ class Predicate(Folder): ...@@ -137,6 +148,7 @@ class Predicate(Folder):
elif (bc in membership_criterion_base_category_list): elif (bc in membership_criterion_base_category_list):
tested_base_category[bc] = tested_base_category[bc] or \ tested_base_category[bc] = tested_base_category[bc] or \
context.isMemberOf(c) context.isMemberOf(c)
# LOG('predicate test', 0, # LOG('predicate test', 0,
# '%s after single membership to %s' % \ # '%s after single membership to %s' % \
# (tested_base_category[bc], c)) # (tested_base_category[bc], c))
......
...@@ -55,8 +55,9 @@ class DomainTool(BaseTool): ...@@ -55,8 +55,9 @@ class DomainTool(BaseTool):
# (some users are not able to see resource's price) # (some users are not able to see resource's price)
security.declarePublic('searchPredicateList') security.declarePublic('searchPredicateList')
def searchPredicateList(self, context, test=1, sort_method=None, def searchPredicateList(self, context, test=1, sort_method=None,
ignored_category_list=None, filter_method=None, ignored_category_list=None,
acquired=1, **kw): tested_base_category_list=None,
filter_method=None, acquired=1, **kw):
""" """
Search all predicates which corresponds to this particular Search all predicates which corresponds to this particular
context. context.
...@@ -69,6 +70,10 @@ class DomainTool(BaseTool): ...@@ -69,6 +70,10 @@ class DomainTool(BaseTool):
not want to test. For example, we might want to not test the not want to test. For example, we might want to not test the
destination or the source of a predicate. 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 - the acquired parameter allows to define if we want to use
acquisition for categories. By default we want. acquisition for categories. By default we want.
""" """
...@@ -127,23 +132,32 @@ class DomainTool(BaseTool): ...@@ -127,23 +132,32 @@ class DomainTool(BaseTool):
checked_column_list.append('%s_range_max' % property) checked_column_list.append('%s_range_max' % property)
# Add predicate.uid for automatic join # Add predicate.uid for automatic join
sql_kw['predicate.uid'] = '!=0' sql_kw['predicate.uid'] = '!=0'
where_expression = ' AND '.join(expression_list) where_expression = ' AND \n'.join(expression_list)
# Add category selection # Add category selection
if tested_base_category_list is None:
if acquired: if acquired:
category_list = context.getAcquiredCategoryList() category_list = context.getAcquiredCategoryList()
else: else:
category_list = context.getCategoryList() category_list = context.getCategoryList()
else:
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: if len(category_list)==0:
category_list = ['NULL'] category_list = ['NULL']
category_expression = portal_categories.buildSQLSelector( category_expression = portal_categories.buildSQLSelector(
category_list, category_list,
query_table='predicate_category') query_table='predicate_category')
if len(where_expression) > 0: if len(where_expression) > 0:
where_expression = '(%s) AND (%s)' % \ where_expression = '(%s) AND \n(%s)' % \
(where_expression,category_expression) (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
# Add predicate_category.uid for automatic join # Add predicate_category.uid for automatic join
sql_kw['predicate_category.uid'] = '!=0' sql_kw['predicate_category.uid'] = '!=0'
...@@ -157,7 +171,9 @@ class DomainTool(BaseTool): ...@@ -157,7 +171,9 @@ class DomainTool(BaseTool):
# LOG('searchPredicateList, result_list before test', 0, # LOG('searchPredicateList, result_list before test', 0,
# [x.getObject() for x in sql_result_list]) # [x.getObject() for x in sql_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==0 or predicate.test(context): if test==0 or predicate.test(
context,
tested_base_category_list=tested_base_category_list):
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 filter_method is not None: 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