Wednesday, April 14, 2010

Change creator programmatically

In order to change an object's Creator from a script or another piece of code, use setCreators(new_creator,). Mark the comma: apparently, the method takes a list as input.

I used this in a view class which mass-changes ownership:
    def changeOwnership(self, obj, userid):
""" Change ownership of obj to userid """
membership = getToolByName(self.context, 'portal_membership')
user = membership.getMemberById(userid)
roles = list(obj.get_local_roles_for_userid(userid))
if 'Owner' not in roles:
obj.manage_setLocalRoles(userid, roles)

I had a look at the internals of to find out what i had to do in order to make this work.

1 comment:

David said...

You've saved me again. That's exactly what I've looking for and it works a charm. Thanks heaps!