Commit 55420954 authored by Jérome Perrin's avatar Jérome Perrin

allow to specify in CatalogTool the max number of result to retrieve by

default. Use this feature in testERP5Catalog not to have to create more than
1000 documents.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@13387 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 55538fae
......@@ -73,8 +73,6 @@ try:
except ImportError:
pass
DEFAULT_RESULT_LIMIT = 1000
def getSecurityProduct(acl_users):
"""returns the security used by the user folder passed.
(NuxUserGroup, ERP5Security, or None if anything else).
......@@ -183,7 +181,8 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
id = 'portal_catalog'
meta_type = 'ERP5 Catalog'
security = ClassSecurityInfo()
default_result_limit = 1000
manage_options = ( { 'label' : 'Overview', 'action' : 'manage_overview' },
) + ZCatalog.manage_options
......@@ -511,7 +510,7 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
kw[ 'expires' ] = { 'query' : now, 'range' : 'min' }
query = self.getSecurityQuery(query=query, **kw)
kw.setdefault('limit', DEFAULT_RESULT_LIMIT)
kw.setdefault('limit', self.default_result_limit)
return ZCatalog.searchResults(self, query=query, **kw)
__call__ = searchResults
......@@ -520,7 +519,7 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
def unrestrictedSearchResults(self, REQUEST=None, **kw):
"""Calls ZSQLCatalog.searchResults directly without restrictions.
"""
kw.setdefault('limit', DEFAULT_RESULT_LIMIT)
kw.setdefault('limit', self.default_result_limit)
return ZCatalog.searchResults(self, REQUEST, **kw)
# We use a string for permissions here due to circular reference in import
......@@ -551,7 +550,7 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
# #kw[ 'expires' ] = { 'query' : now, 'range' : 'min' }
query = self.getSecurityQuery(query=query, **kw)
kw.setdefault('limit', DEFAULT_RESULT_LIMIT)
kw.setdefault('limit', self.default_result_limit)
return ZCatalog.countResults(self, query=query, **kw)
security.declarePrivate('unrestrictedCountResults')
......
......@@ -1329,11 +1329,18 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor):
message = 'Test Limit'
ZopeTestCase._print('\n%s ' % message)
LOG('Testing... ',0,message)
#Create 1002 Organisations
for i in xrange(1002):
self._makeOrganisation(title='abc%s' % (i),description='abc')
self.assertEqual(1000,len(self.getCatalogTool()(portal_type='Organisation')))
self.assertEqual(1002,len(self.getCatalogTool()(portal_type='Organisation',limit=None)))
ctool = self.getCatalogTool()
old_default_result_limit = cool.default_result_limit
max_ = 10
#Create max + 2 Organisations
for i in xrange(max_ + 2):
self._makeOrganisation(title='abc%s' % (i), description='abc')
self.assertEqual(max_,
len(self.getCatalogTool()(portal_type='Organisation')))
self.assertEqual(max + 2,
len(self.getCatalogTool()(portal_type='Organisation', limit=None)))
ctool.default_result_limit = old_default_result_limit
def playActivityList(self, method_id_list):
get_transaction().commit()
......
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