**I am using Plone. I have Staff and Faculty objects stored under the following url
http://mysite/yc1/portal_college/
I would like to iterate over all the Faculty Object and make modifications
So far, I have been using QueryCatalog. When I use this and update the object, it changes in the instance of the code that I am running, but it does not change in the ZODB database.
What is the best way of doing this?
My Code:
from AccessControl import getSecurityManager
from StringIO import StringIO
from Products.CMFCore.utils import getToolByName
membership = getToolByName(context, 'portal_membership')
username = context.portal_membership.getAuthenticatedMember().getUserName()
buf = StringIO()
items = list(context.portal_catalog.queryCatalog({
"portal_type":("Faculty"),
"path":"/yc1/portal_college/bbharosay",
"sort_on" : "created" }))
context.manage_setLocalRoles(username, ['Manager', 'Owner','Editor'])
print >> buf, "Found %d items to be Updated" % len(items)
getSecurityManager().checkPermission('View', context)
roles2 = [r['name'] for r in context.rolesOfPermission('View') if r['selected']]
count = 0
for b in items:
obj = b.getObject()
d='dummyvalue'
print obj.getADStatus()
try:
print obj.getADStatus()
obj.setFirst_name(d)
obj.setLast_name(d)
obj.setTeachingTitle(d)
obj.setOtherTitle(d)
obj.setEmail(d);
obj.setOfficePhone(d)
obj.setOfficeLocation(d)
obj.setDept(d);
obj.setEmployeeType(d)
obj.setDivision(d)
obj.setCurrentStatus(d)
obj.setOrgStatus(d)
print obj.getFirst_name()
print '\n'
print obj.getLast_name()
obj.setLast_namek('budwa')
print "obj lastname="+obj.getLast_name()
modified(obj)
obj.reindexObject()
except Exception:
#pass
print Exception
count=count+1
print count
print 'done'
return buf.getvalue(), printed**