[Zope-dev] problem adding ZClass instances via DTML

Gilles Lenfant gilles@objectis.net
Tue, 26 Feb 2002 22:43:09 +0100


Mark,

It seems you forget the id of your new object !!
I use do do it in Python script (easier for testing initial data from =
request). But you can translate in DTML if you prefer...
# Test initial data from REQUEST and redirect somewhere if required
...
# Create the new ZClass based object
newobject =3D =
somefolderishobject.manage_addProduct['MyProduct'].MyZClass.createInObjec=
tManager(newId, context.REQUEST)
# May add computed values to properties
props =3D {}
props['created'] =3D DateTime()
props['creator'] =3D context.REQUEST.AUTHENTICATED_USER.getUserName()
...
newobject.propertysheets.mypropertysheet.manage_changeProperties(props)
# Redirect somewhere or return the object or whatever

HTH

--Gilles
----- Original Message -----=20
From: "Mark James Adams" <mja27@cornell.edu>
To: <zope-dev@zope.org>
Sent: Tuesday, February 26, 2002 8:25 PM
Subject: [Zope-dev] problem adding ZClass instances via DTML


: I'm following the instructions in "Adding ZClass Instances=20
: Programmatically" (http://www.zope.org/Members/tazzzzz/addZClasses), =
but=20
: Zope always returns an error.
:=20
: Using the code from a DTMLMethod in another ZClass in the same =
product:
:=20
: <dtml-with "manage_addProduct['MyProduct']">
: <dtml-call "MyZClass_add(_.None, NoRedir=3D1)">
: </dtml-with>
:=20
: I get the error:
:=20
: File /usr/local/Zope/lib/python/DocumentTemplate/DT_Util.py, line 339, =

: in eval (Object: MyZClass.createInObjectManager(REQUEST['id'], =
REQUEST))=20
: (Info: REQUEST) File , line 0, in ? NameError: MyZClass
:=20
: So this is clearly having a problem finding MyZClass from the=20
: MyZClass_add method.
:=20
: I then noticed that, according to the HowTo, if you are instantiating =
a=20
: ZClass from within another ZClass, you only need the code:
:=20
: <dtml-call "MyZClass_add(_.None, NoRedir=3D1)">
:=20
: However, this gives the error:
:=20
: File /usr/local/Zope/lib/python/DocumentTemplate/DT_Util.py, line 339, =

: in eval (Object: MyZClass_add(_.None, NoRedir=3D1)) (Info: _) File , =
line=20
: 0, in ? NameError: MyZClass_add
:=20
: Any suggestions?
:=20
: Thanks.
:=20
: --
: Mark James Adams
: mark@raysend.com | mja27@cornell.edu
:=20
:=20
:=20
: _______________________________________________
: Zope-Dev maillist  -  Zope-Dev@zope.org
: http://lists.zope.org/mailman/listinfo/zope-dev
: **  No cross posts or HTML encoding!  **
: (Related lists -=20
:  http://lists.zope.org/mailman/listinfo/zope-announce
:  http://lists.zope.org/mailman/listinfo/zope )
:=20