[Zope] Please Help! - Changing instance owner with external script...

Rob Foster rob@thefosters.com
Tue, 6 Nov 2001 20:14:03 -0700


Hi there,

I've been trying to get the external script below to work with little 
success (I found it on ZopeLabs):

def custom_changeOwnership(self, username, obj):
     acl_users = getattr(self, 'acl_users')
     #UserFolder source
     user = acl_users.getUser(username).__of__(acl_users)
     obj.changeOwnership(user)

--------------------------------------------------------------------------------------------------------

I've got a script that grabs a username value "name" from a form and 
creates an instance in an adjacent directory. Using your script, I'm 
trying to get the owner changed to the same value... with no luck. I 
keep getting messages like this:

--------------------------------------------------------------------------------------------------------

Error Type: AttributeError
Error Value: changeOwnership


Traceback (innermost last):
   File /filepath/lib/python/ZPublisher/Publish.py, line 223, in 
publish_module
   File /filepath/lib/python/ZPublisher/Publish.py, line 187, in publish
   File /filepath/lib/python/Zope/__init__.py, line 226, in 
zpublisher_exception_hook
     (Object: LockableItem)
   File /filepath/lib/python/ZPublisher/Publish.py, line 171, in publish
   File /filepath/lib/python/ZPublisher/mapply.py, line 160, in mapply
     (Object: checkUsers)
   File /filepath/lib/python/ZPublisher/Publish.py, line 112, in 
call_object
     (Object: checkUsers)
   File /filepath/lib/python/Shared/DC/Scripts/Bindings.py, line 324, in 
__call__
     (Object: checkUsers)
   File /filepath/lib/python/Shared/DC/Scripts/Bindings.py, line 354, in 
_bindAndExec
     (Object: checkUsers)
   File /filepath/lib/python/Products/PythonScripts/PythonScript.py, line 
363, in _exec
     (Object: checkUsers)
     (Info: ({'script': <PythonScript instance at edb860>, 'context': 
<Folder instance at c523c0>, 'container': <Folder instance at c523c0>, 
'traverse_subpath': []}, (), {}, None))
   File Script (Python), line 26, in checkUsers
     (Object: guarded_getitem)
   File /filepath/lib/python/Products/ExternalMethod/ExternalMethod.py, 
line 281, in __call__
     (Object: customChangeOwnership)
     (Info: (('dfd', 'dfd'), {}, None))
   File /filepath/Extensions/custom_zmgmt.py, line 5, in 
custom_changeOwnership
     (Object: LockableItem)
AttributeError: (see above)

  --------------------------------------------------------------------------------------------------------

Here's the script:

context.REQUEST.set('id', request.form['name'])
my_context= context.members.manage_addProduct['MyProduct']
my_context.Member_add(my_context,context.REQUEST, NoRedir=1)

context.customChangeOwnership(request.form['name'], 
context.members.REQUEST['name'])

  --------------------------------------------------------------------------------------------------------


I think maybe part of the problem is that I don't know what "context" 
means exactly and how to use it. I'm guessing this error is caused 
because an object can't be found?

Any help would be greatly appreciated.

Thanks,
Rob