[Erp5-dev] More than 1000 objects...
Yoshinori Okuji
yo at nexedi.com
Tue Jan 16 18:05:10 CET 2007
On Tuesday 16 January 2007 17:18, Łukasz Nowak wrote:
> Hello,
>
> I was doing some conversion in my ERP5 site. Many scripts looks like:
>
> for o in [x.getObject() for x in \
> context.portal_catalog(portal_type=pt)]:
> o.activate().something()
>
> I know, that catalog results are cut to 1000 objects. Well, there are my
> questions:
>
> - how to know from script, that data result is cut to 1000, is any
> exception raised somewhere?
No.
> - are there any guides to write generic conversion scripts, which
> shall be invoked on objects, for example to create window of 500 objects
> and then move this window to next 500 and so on until end of object list?
You can simply supply a limit expression to portal_catalog, with which you can
specify the max number of results and optionally an offset, in much the same
way as with SQL. For example:
params = {'portal_type': pt}
count = int(context.portal_catalog.countResults(**params)[0][0])
max = 1000
for offset in xrange(0, count, max):
for o in context.portal_catalog(limit = (offset, max), **params):
o.getObject().activate().something()
YO
--
Yoshinori Okuji, Nexedi CTO
Nexedi: Consulting and Development of Free / Open Source Software
http://www.nexedi.com
ERP5: Full Featured High End Open Source ERP
http://www.erp5.com
ERP5 Wiki: Developer Zone for ERP5 Community
http://www.erp5.org
More information about the Erp5-dev
mailing list