[Zope] Batch property change of ZCataloged ZClasses
Milos Prudek
milos.prudek@tiscali.cz
Sun, 24 Mar 2002 20:37:29 +0100
I need to loop over a subset of ZCataloged ZClass instances, change a
property, and reindex the ZClass.
A simple approach fails:
for i in context.Catalog_Org(userid=uid):
l=i.userid
l.remove(uid)
rid=i.data_record_id_
obj=context.Catalog_Org.getobject(rid)
obj.propertysheets.data.manage_changeProperties(userid=l)
obj.reindex_object()
The above Python Script will change only one ZClass instance, no matter
how many exist, because when "obj.reindex_object()" is reached, it
causes the loop to end immediately.
A data_record_id caching makes the script work:
rids=[]
for i in context.Catalog_Org(userid=uid):
l=i.userid
l.remove(uid)
rid=i.data_record_id_
rids.append(rid)
obj=context.Catalog_Org.getobject(rid)
obj.propertysheets.data.manage_changeProperties(userid=l)
for rid in rids:
obj=context.Catalog_Org.getobject(rid)
obj.reindex_object()
Is it a bug or feature?
I run Zope 2.4.3 on Linux.
--
Milos Prudek