[Zope] Help! Trying to create an instance and then change the owner...

Rob Foster rob@thefosters.com
Mon, 12 Nov 2001 18:47:51 -0700


--Apple-Mail-1--608415696
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
	charset=US-ASCII;
	format=flowed

First of all, thanks to everyone for their  help.

I've been trying to figure out how to do this one set of things for ages 
now. I've sent countless emails to the newsgroup and I still run into 
problems. Here's my problem, perhaps you can help once more...

I'm creating a site where people will come and signup to become members. 
This is what happens (or should happen):

1. The user fills out a form that has fields to choose their username 
and password along with a confirmation field.
     This form posts the python script below which is called "addUser" (I 
left out the top half of this script which adds a user to the acl_users 
folder)

------------------------------------------------------------------------------------------
request = container.REQUEST
RESPONSE =  request.RESPONSE

request = context.REQUEST
request.set('id', request.form['username'])
tmpObj = context.membersfolder.manage_addProduct['MyProduct']
tmpObj.MyZclass_add(tmpObj, request, NoRedir=1)
------------------------------------------------------------------------------------------

As you can see, this script adds an instance of my zclass (MyZclass) in 
an adjacent folder called "membersfolder" with owner set to my admin 
account.

This works fine, until I add the two lines below which should change the 
owner:

------------------------------------------------------------------------------------------
#THE FOLLOWING LINE IS LINE 27 - SEE THE TRACEBACK BELOW

obj = _.getitem(request.form['username'])
context.custom_changeOwnership(request.form['username'], obj)
------------------------------------------------------------------------------------------

The two lines above are supposed to work with the external script below:

------------------------------------------------------------------------------------------
def custom_changeOwnership(self, username, obj):
     """ explicitly setup changeOwnership for TTW """
     acl_users = getattr(self, 'acl_users')    #UserFolder source
     user = acl_users.getUser(username).__of__(acl_users)
     obj.changeOwnership(user)
------------------------------------------------------------------------------------------

When I add those two lines, I keep getting the following error where 
"foo" is the username I'm typing in the form:

------------------------------------------------------------------------------------------
Error Type: KeyError
Error Value: foo

Traceback (innermost last):
   File 
/Users/rfoster/Desktop/Zope-2.4.1-MOSX/lib/python/ZPublisher/Publish.py, 
line 223, in publish_module
   File 
/Users/rfoster/Desktop/Zope-2.4.1-MOSX/lib/python/ZPublisher/Publish.py, 
line 187, in publish
   File 
/Users/rfoster/Desktop/Zope-2.4.1-MOSX/lib/python/Zope/__init__.py, line 
226, in zpublisher_exception_hook
     (Object: LockableItem)
   File 
/Users/rfoster/Desktop/Zope-2.4.1-MOSX/lib/python/ZPublisher/Publish.py, 
line 171, in publish
   File 
/Users/rfoster/Desktop/Zope-2.4.1-MOSX/lib/python/ZPublisher/mapply.py, 
line 160, in mapply
     (Object: addUser)
   File 
/Users/rfoster/Desktop/Zope-2.4.1-MOSX/lib/python/ZPublisher/Publish.py, 
line 112, in call_object
     (Object: addUser)
   File 
/Users/rfoster/Desktop/Zope-2.4.1-MOSX/lib/python/Shared/DC/Scripts/Bindings.
py, line 324, in __call__
     (Object: addUser)
   File 
/Users/rfoster/Desktop/Zope-2.4.1-MOSX/lib/python/Shared/DC/Scripts/Bindings.
py, line 354, in _bindAndExec
     (Object: addUser)
   File 
/Users/rfoster/Desktop/Zope-2.4.1-MOSX/lib/python/Products/PythonScripts/PythonScript.
py, line 363, in _exec
     (Object: addUser)
     (Info: ({'script': <PythonScript instance at fdaf60>, 'context': 
<Folder instance at ffeaf0>, 'container': <Folder instance at 
ffeaf0>, '_': <TemplateDict object at 0xcbfa20>, 
'traverse_subpath': []}, (), {}, None))
   File Script (Python), line 27, in addUser
     (Object: guarded_getitem)
KeyError: (see above)
------------------------------------------------------------------------------------------


I should also note that the binding in my script is set to: "_"

Any help would be appreciated. I must really suck. I've been working on 
this same darn problem for almost three weeks now... ugh. I should also 
mention that I'm pretty green... All this code was written by others and 
I'm just trying to get it all to work right (I'm no programmer)

Thanks in advance,
Rob

--Apple-Mail-1--608415696
Content-Transfer-Encoding: 7bit
Content-Type: text/enriched;
	charset=US-ASCII

First of all, thanks to everyone for their  help.


I've been trying to figure out how to do this one set of things for
ages now. I've sent countless emails to the newsgroup and I still run
into problems. Here's my problem, perhaps you can help once more... 


I'm creating a site where people will come and signup to become
members. This is what happens (or should happen):


1. The user fills out a form that has fields to choose their username
and password along with a confirmation field.

    This form posts the python script below which is called "addUser"
(I left out the top half of this script which adds a user to the
acl_users folder)


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

request = container.REQUEST

RESPONSE =  request.RESPONSE


request = context.REQUEST

request.set('id', request.form['username'])

tmpObj = context.membersfolder.manage_addProduct['MyProduct']

tmpObj.MyZclass_add(tmpObj, request, NoRedir=1)

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


As you can see, this script adds an instance of my zclass (MyZclass)
in an adjacent folder called "membersfolder" with owner set to my
admin account.


This works fine, until I add the two lines below which should change
the owner:


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

#THE FOLLOWING LINE IS LINE 27 - SEE THE TRACEBACK BELOW


obj = _.getitem(request.form['username'])

context.custom_changeOwnership(request.form['username'], obj)

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


The two lines above are supposed to work with the external script
below:


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

def custom_changeOwnership(self, username, obj):

    """ explicitly setup changeOwnership for TTW """

    acl_users = getattr(self, 'acl_users')    #UserFolder source

    user = acl_users.getUser(username).__of__(acl_users)

    obj.changeOwnership(user)

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


When I add those two lines, I keep getting the following error where
"foo" is the username I'm typing in the form:


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

<bold><fontfamily><param>Arial</param><bigger><bigger>Error Type:
KeyError</bigger></bigger></fontfamily></bold><fontfamily><param>Arial</param><bigger><bigger>

<bold>Error Value: foo

</bold></bigger></bigger></fontfamily><fixed><fontfamily><param>Courier New</param>

Traceback (innermost last):

  File
/Users/rfoster/Desktop/Zope-2.4.1-MOSX/lib/python/ZPublisher/Publish.py,
line 223, in publish_module

  File
/Users/rfoster/Desktop/Zope-2.4.1-MOSX/lib/python/ZPublisher/Publish.py,
line 187, in publish

  File
/Users/rfoster/Desktop/Zope-2.4.1-MOSX/lib/python/Zope/__init__.py,
line 226, in zpublisher_exception_hook

    (Object: LockableItem)

  File
/Users/rfoster/Desktop/Zope-2.4.1-MOSX/lib/python/ZPublisher/Publish.py,
line 171, in publish

  File
/Users/rfoster/Desktop/Zope-2.4.1-MOSX/lib/python/ZPublisher/mapply.py,
line 160, in mapply

    (Object: addUser)

  File
/Users/rfoster/Desktop/Zope-2.4.1-MOSX/lib/python/ZPublisher/Publish.py,
line 112, in call_object

    (Object: addUser)

  File
/Users/rfoster/Desktop/Zope-2.4.1-MOSX/lib/python/Shared/DC/Scripts/Bindings.py,
line 324, in __call__

    (Object: addUser)

  File
/Users/rfoster/Desktop/Zope-2.4.1-MOSX/lib/python/Shared/DC/Scripts/Bindings.py,
line 354, in _bindAndExec

    (Object: addUser)

  File
/Users/rfoster/Desktop/Zope-2.4.1-MOSX/lib/python/Products/PythonScripts/PythonScript.py,
line 363, in _exec

    (Object: addUser)

    (Info: ({'script': <<PythonScript instance at fdaf60>, 'context':
<<Folder instance at ffeaf0>, 'container': <<Folder instance at
ffeaf0>, '_': <<TemplateDict object at 0xcbfa20>, 'traverse_subpath':
[]}, (), {}, None))

  File Script (Python), line 27, in addUser

    (Object: guarded_getitem)

KeyError: (see above)

</fontfamily></fixed>------------------------------------------------------------------------------------------<fixed><fontfamily><param>Courier New</param>

</fontfamily></fixed>


I should also note that the binding in my script is set to: "_"


Any help would be appreciated. I must really suck. I've been working
on this same darn problem for almost three weeks now... ugh. I should
also mention that I'm pretty green... All this code was written by
others and I'm just trying to get it all to work right (I'm no
programmer)


Thanks in advance,

Rob


--Apple-Mail-1--608415696--