adding a python script from a python script
Gentle Zopae Please can anyone enlighten what is the correct syntax to use 'manage_addPythonScript ' method inside of a Pythonscript? I want to pass in the id name, and a few parameters. thanks - Jason ___________________________________________________________ Jason CUNLIFFE = NOMADICS['Interactive Art and Technology']
This is a frequently asked question. There is a good write up about using Python Scripts in the ZopeBook Chapter 5 (Creating Basic Zope Applications (has examples)): http://www.zope.org/Members/michel/ZB/ The API Reference (Appendix B): http://www.zope.org/Members/michel/ZB/AppendixB.dtml HTH, Ron Jason Cunliffe wrote:
Gentle Zopae
Please can anyone enlighten what is the correct syntax to use 'manage_addPythonScript ' method inside of a Pythonscript?
I want to pass in the id name, and a few parameters.
thanks
- Jason
___________________________________________________________ Jason CUNLIFFE = NOMADICS['Interactive Art and Technology']
_______________________________________________ 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 )
----- Original Message ----- From: Ronald L. Chichester <complaw@hal-pc.org>
This is a frequently asked question.
There is a good write up about using Python Scripts in the ZopeBook
Chapter 5 (Creating Basic Zope Applications (has examples)):
http://www.zope.org/Members/michel/ZB/
The API Reference (Appendix B):
Ron Thanks for the solid tips, but alas it's hardly a well answered FAQ yet. I had looked at the links above already. But checked them again still finding nothing to help me. So I tried a search on zope.org for 'manage_addPythonScript' da:-( Then I entered 'manage_addPythonScript' in zope.org Resources which returned 3 links including my post and your reply.. but hitting 'next' led to some more complex techniques in a post From: Jim Washington <jwashin@v...> Date: Mon Jan 29, 2001 7:54pm Subject: Re: [Zope] porting from Python Methods to PythonScripts in 2.3.0;LoginManager too http://groups.yahoo.com/group/zope/message/50218 But buried there lies the answer.. ---------------------------------------------- How-To add a Python Script from a Python script 1. create Python Script "addPyScript" for example 2. in the parameter field include idname='mypyscript' 3. in the body of the script enter: container.manage_addProduct['PythonScripts'].manage_addPythonScript(idname) ----------------------------------------------- Ok So far so good. Since I am setting a named default, I get an error mesasge if I try it again Error Type: Bad Request Error Value: The id "mypyscript" is invalid--it is already in use. So I need to check first from the pythonscript if such an object already exists in the current folder. In DTML this would be the regular <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? I tried modifying the body ab ove like this: if idname: return 'An object called %s already exists. Please select a new name' % idname else: container.manage_addProduct['PythonScripts'].manage_addPythonScript(idname) but that is not right. How to get Python script to take the value of the parameter field, and check for an object of that name in the same folder? Till now, I cannot seem to find any good place for reading Python Script examples. I suggest it could really helpful to add a separate section at http://www.zope.org/Documentation called 'Python Scripts' thanks - Jason ___________________________________________________________ Jason CUNLIFFE = NOMADICS['Interactive Art and Technology']
Jason Cunliffe wrote:
So I tried a search on zope.org for 'manage_addPythonScript' da:-(
Well, that's always gonna get you nothing ;-) ZCatalog strips out things like '_', '.', ',' and short words making it almost useless for this kind of search. Point Google at www.zope.org or wait from drop in indexes with customisable splitters (see zope-dev@zope.org). cheers, Chris
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
participants (3)
-
Chris Withers -
Jason Cunliffe -
Ronald L. Chichester