Commit 2feed567 authored by Julien Muchembled's avatar Julien Muchembled

Deprecate sort_method parameter in DomainTool.searchPredicateList since cmp...

Deprecate sort_method parameter in DomainTool.searchPredicateList since cmp parameter in sorting methods is slow and deprecated.
Add new sort_key_method parameter that is passed as key parameter to list.sort.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@26242 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 8c707d3a
......@@ -60,7 +60,7 @@ class DomainTool(BaseTool):
ignored_category_list=None,
tested_base_category_list=None,
filter_method=None, acquired=1,
strict=True, **kw):
strict=True, sort_key_method=None, **kw):
# XXX: about "strict" parameter: This is a transition parameter,
# allowing someone hitting a bug to revert to original behaviour easily.
# It is not a correct name, as pointed out by Jerome. But instead of
......@@ -68,9 +68,11 @@ class DomainTool(BaseTool):
"""
Search all predicates which corresponds to this particular
context.
- The sort_method parameter allows to give a method which will be
used in order to sort the list of predicates found. The most
- sort_method parameter is deprecated: use sort_key_method instead.
- sort_key_method parameter is passed to list.sort as key parameter if it
is not None. This allows to sort the list of predicates found. The most
important predicate is the first one in the list.
- ignored_category_list: this is the list of category that we do
......@@ -203,8 +205,12 @@ class DomainTool(BaseTool):
# LOG('searchPredicateList, result_list before sort', 0, result_list)
if filter_method is not None:
result_list = filter_method(result_list)
if sort_method is not None:
result_list.sort(sort_method)
if sort_key_method is not None:
result_list.sort(key=sort_key_method)
elif sort_method is not None:
LOG('searchPredicateList', 0,
'sort_method parameter is deprecated: sort_key_method instead')
result_list.sort(cmp=sort_method)
# LOG('searchPredicateList, result_list after sort', 0, result_list)
return result_list
......
......@@ -376,6 +376,10 @@ class TestDomainTool(TestPredicateMixIn):
return -1
return 0
def sort_key_method(x):
hasCellContent = getattr(x, 'hasCellContent', None)
return bool(hasCellContent and hasCellContent(base_id='path'))
get_transaction().commit()
self.tic()
domain_tool = self.getDomainTool()
......@@ -384,16 +388,24 @@ class TestDomainTool(TestPredicateMixIn):
'variation/%s/blue' % self.resource.getRelativeUrl()])
mapped_value = domain_tool.generateMappedValue(context,sort_method=sort_method)
self.assertEquals(mapped_value.getProperty('base_price'),45)
mapped_value = domain_tool.generateMappedValue(context,sort_key_method=sort_key_method)
self.assertEquals(mapped_value.getProperty('base_price'),45)
context = self.resource.asContext(
categories=['resource/%s' % self.resource.getRelativeUrl(),
'variation/%s/red' % self.resource.getRelativeUrl()])
mapped_value = domain_tool.generateMappedValue(context,sort_method=sort_method)
self.assertEquals(mapped_value.getProperty('base_price'),26)
mapped_value = domain_tool.generateMappedValue(context,sort_key_method=sort_key_method)
self.assertEquals(mapped_value.getProperty('base_price'),26)
# Now check the price
self.assertEquals(self.resource.getPrice(context=self.resource.asContext(
categories=['resource/%s' % self.resource.getRelativeUrl(),
'variation/%s/blue' % self.resource.getRelativeUrl()]),
sort_method=sort_method),45)
self.assertEquals(self.resource.getPrice(context=self.resource.asContext(
categories=['resource/%s' % self.resource.getRelativeUrl(),
'variation/%s/blue' % self.resource.getRelativeUrl()]),
sort_key_method=sort_key_method),45)
def test_06_SQLQueryDoesNotReturnTooManyPredicates(self, quiet=0, run=run_all_test):
if not run: return
......
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