Discussion:
[Erp5-dev] More than 1000 objects...
Łukasz Nowak
2007-01-16 16:18:30 UTC
Permalink
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?
- 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?

Thanks,
Luke
--
?ukasz Nowak R&D Ventis http://www.ventis.com.pl/
tel: +48 32 768 16 85 fax: +48 32 392 10 61
``Use the Source, Luke...''
Yoshinori Okuji
2007-01-16 17:05:10 UTC
Permalink
Post by Łukasz Nowak
Hello,
for o in [x.getObject() for x in \
o.activate().something()
I know, that catalog results are cut to 1000 objects. Well, there are my
- how to know from script, that data result is cut to 1000, is any
exception raised somewhere?
No.
Post by Łukasz Nowak
- 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
Loading...