Please Help! - Changing instance owner with external script...
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
Ok, the custom_changeOwnership method is expecting (basically) two arguments. The first one is the username that you would like to change ownership to, and the second is the actual object that you would like to change the owner of, not simply the name of the objext.. So, you have to first get an object reference (using getitem) I'm guessing you are creating an object with an id of the username in your script, so you would do something like: request = context.REQUEST request.set('id', request.form['name']) tmpObj = context.members.manage_addProduct['MyProduct'] tmpObj.Member_add(tmpObj, request, NoRedir=1) obj = context.getItem(request.form['name']) context.custom_changeOwnership(request.form['name'], obj) HTH, Adam On Wed, 2001-11-07 at 03:14, Rob Foster wrote:
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
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
-- "There's never enough time to do | M. Adam Kendall all the nothing you want." | mak@kha0s.org -Bill Watterson (Calvin and Hobbes) | http://www.zopelabs.com
participants (2)
-
M. Adam Kendall -
Rob Foster