[Zope] adding a python script from a python script

Chris Withers chrisw@nipltd.com
Sun, 01 Apr 2001 23:56:43 +0100


> container.manage_addProduct['PythonScripts'].manage_addPythonScript(idname)

To be fair, that's a pretty standard way of creating an instance of a product in
Zope. If you've done any ZClasses programming, it should be familiar...

> Ok So far so good. Since I am setting a named default, 

Simplest solution might be to not provide a default ;-)

> <dtml-if expr="mypyscript">
>   That object already exists. Choose another name.
> <dtml-else>
>   ... manage_addPythonScript.. code goes here
> </dtml-if>
> 
> Please how do I do this basic task in Python Script?

if hasattr(context,idname):
  # That object already exists. Choose another name.
else:
  context.manage_addProduct['PythonScripts'].manage_addPythonScript(idname)

cheers,

Chris