[Zope] Programmatically creating instances of a ZClass

Gouzy Nicolas nicolas@opixido.com
Thu, 5 Sep 2002 10:34:49 +0200


Your constructor "MyProduct_add" is a DTML Method, isn't it ?
Delete it and replace by a Python Script called "MyProduct_add"

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
# MyProduct_add source                             #
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D

Parameter List:=20
id, REQUEST=3DNone

Code:
obj=3Dcontext.MyProduct.createInObjectManager(id=3Did, {})
  =20
if REQUEST is not None:
    try:
         u=3Dcontext.DestinationURL()
    except:
         u=3DREQUEST['URL2']
    REQUEST.RESPONSE.redirect(u+'/manage_workspace')

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D

Now, you can write in a Python Script:
container.manage_addProduct['MyProduct'].MyProduct_add(id=3D'myBeautifulO=
bject')

On Wednesday 04 September 2002 21:14, Borislav wrote:
> Gouzy Nicolas wrote:
> > You can try:
> >
> > container.manage_addProduct['MyProduct'].MyProduct_add()
> >
> > MyProduct_add is the constructor of the ZClass MyProduct
>
> How do I pass the object id to this constructor? Seems that it reads it
> from the REQUEST, but I can't assign to REQUEST in a python script. Thi=
s
> code:
>
> context.REQUEST['id'] =3D myObjectId
> container.manage_addProduct['MyProduct'].MyProduct_add()
>
> produces an error:
>
> Error Type: TypeError
> Error Value: object does not support item or slice assignment
>
> Am I missing something?
>
> --Borislav

--=20

Nicolas Gouzy
Chef de Projet / Ing=E9nieur de D=E9veloppement

OPIXIDO
9, cit=E9 paradis 75010 Paris
FRANCE
tel : 01 40 22 92 46 ou 47
fax : 01 40 22 92 44