Plone bulk update of default values for new attribute
Tuesday, September 16th, 2008Scenario: I added a new attribute “orderPriority” to a few different archetypes based content types. These attributes had default values. As this is an existing site, there were 400 or so existing objects that had not picked up these default values - i.e. they would only pick up the value after they had been re-saved. To make sure these objects picked up the default value I created a skin script, which I proxied as manager (watch out for indentation here, really must find a better way to display preformatted code):-
catalog = context.portal_catalog
# objects are all in folder /directory/listing/ listing_folder = getattr(context.directory, 'listing') for brain in catalog(portal_type = ['NameOfMyContentType']): print brain.portal_type + ' ' + brain.id + ' ' + brain.Title listing = getattr(listing_folder, brain.id) #this gets the default vakue from the schema order = listing.getOrderPriority() #this sets it listing.setOrderPriority(order) return printed
I needed to be able to sort by this field in a catalog query/ Topic/SmartFolder/Collection so, so I then added the field as a fielindex in the portal catalog, reindexed the catalog (ZMI) and used the collection edit options in site setup to add it as a field