[Zope3-Users] updating objects in ZODB
Stephan Richter
srichter at cosmos.phy.tufts.edu
Fri Feb 10 17:03:09 EST 2006
On Friday 10 February 2006 05:15, Lorenzo Gil Sanchez wrote:
> Any pointer to documentation about this or to an example application
> that does this will be very helpful.
Here is a generations script (snippet) I wrote for SchoolTool:
def fixPermissionMap(obj):
if isinstance(obj, PersistentSecurityMap):
for pkey, data in obj._byrow.items():
if pkey.startswith('schoolbell'):
obj._byrow['schooltool' + pkey[10:]] = data
del obj._byrow[pkey]
for key, data in obj._bycol.items():
for pkey, pdata in data.items():
if pkey.startswith('schoolbell'):
obj._bycol[key]['schooltool' + pkey[10:]] = pdata
del obj._bycol[key][pkey]
def evolve(context):
storage = context.connection._storage
next_oid = None
# Note: Loop through all persistent, active objects.
while True:
oid, tid, data, next_oid = storage.record_iternext(next_oid)
obj = context.connection.get(oid)
# Make sure that we tell all objects that they have been changed. Who
# cares whether it is true! :-)
# Note: Only needed if you want to only update class references
obj._p_activate()
obj._p_changed = True
# Now fix up other things
fixAnnotations(obj)
fixCalendar(obj)
fixTimetables(obj)
fixOverlaidCalendars(obj)
fixPermissionMap(obj)
if next_oid is None:
break
Regards,
Stephan
--
Stephan Richter
CBU Physics & Chemistry (B.S.) / Tufts Physics (Ph.D. student)
Web2k - Web Software Design, Development and Training
More information about the Zope3-users
mailing list