[Zope] Adding a ZClass instance in python

Chris McDonough chrism@zope.com
Thu, 30 Aug 2001 22:03:14 -0400


(untested) You may need to bind the namespace to a variable ('_') in the
bindings tab of the Python Script, then modify the constructor call to:

context.manage_addProduct['MyProduct'].MyZClass_add(_.None, _,
NoRedir=1)


Gilles Lenfant wrote:
> 
> Hi,
> 
> I've read this How-To
> 
> http://www.zope.org/Members/tazzzzz/addZClasses
> 
> But I'm deadly trying to do this in a python script (that's not a ZClass
> method and does not reside in a product), an not in an external method.
> I've deeply tried to find a way but did not succed.
> 
> The creation of ZClass instances through ZMI works perfectly , through the
> usual MyProduct/MyZClass_addForm and MyZClass_add
> 
> All I do is this (translation into python script of the DTML method from
> above mentioned URL):
> 
> context.REQUEST.set('id', myNewId)
> context.manage_addProduct['MyProduct'].MyZClass_add(_.None, NoRedir=1)
> return 'Done'
> 
> I got this...
> 
> Error Type: NameError
> Error Value: MyZClass
> 
> [VERY LONG TRACEBACK FINISHING WITH]
> 
>     (Object: MyZClass_add)
>   File
> /usr/local/Zope-2.3.3-linux2-x86/lib/python/DocumentTemplate/DT_With.py,
> line 138, in render
>     (Object: MyZClass.createInObjectManager(REQUEST['id'], REQUEST))
>   File
> /usr/local/Zope-2.3.3-linux2-x86/lib/python/DocumentTemplate/DT_Util.py,
> line 339, in eval
>     (Object: MyZClass.createInObjectManager(REQUEST['id'], REQUEST))
>     (Info: REQUEST)
>   File <string>, line 0, in ?
> NameError: (see above)
> 
> Does someone have an idea ?
> 
> Many thanks in advance !
> 
> --Gilles
> 
> _______________________________________________
> 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 )

-- 
Chris McDonough                           Zope Corporation
http://www.zope.org                    http://www.zope.com

""" Killing hundreds of birds with thousands of stones """