Adding a ZClass instance in python
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
(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 """
Chris, Thanks but the punishment is always the same (error message)... When called in this condition, MyZClass_add method claims there is no MyZClass (NameError) !!?? Can't understand this... Looked so many times for a typo error I did not find... --Gilles ----- Original Message ----- From: "Chris McDonough" <chrism@zope.com> To: "Gilles Lenfant" <glenfant@bigfoot.com> Cc: <zope@zope.org> Sent: Friday, August 31, 2001 4:03 AM Subject: Re: [Zope] Adding a ZClass instance in python
(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 """
_______________________________________________ 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 )
Gilles Lenfant writes:
context.REQUEST.set('id', myNewId) context.manage_addProduct['MyProduct'].MyZClass_add(_.None, NoRedir=1) return 'Done' Use:
my_context= context.manage_addProduct['MyProduct'] my_context.MyZClass_add(my_context,context.REQUEST, NoRedir=1) and please keep in mind: *WHENEVER* you call a DTML object explicitely (i.e. other than within DTML "name" parameters), you *MUST* pass in the correct context. There is no longer any magic, that does it for you. Dieter
participants (3)
-
Chris McDonough -
Dieter Maurer -
Gilles Lenfant