Using filesystem Python Scripts
I am in the process of creating a Python Product for Zope with the following directory structure under my Products directory. -FGDC __init__.py <all other .py modules that make up the metatypes of the product> -dtml <my dtml forms> manage_propertiesForm.dtml -scripts processProperties.py I try to execute the script, processProperties, from inside manage_propertiesForm.dtml. Right now, I am using a simple <dtml-var "processProperties"> call. However, I get a NameError saying that processProperties is not defined. Here is my traceback: Traceback (innermost last): Module ZPublisher.Publish, line 98, in publish Module ZPublisher.mapply, line 88, in mapply Module ZPublisher.Publish, line 39, in call_object Module Shared.DC.Scripts.Bindings, line 252, in __call__ Module Shared.DC.Scripts.Bindings, line 283, in _bindAndExec Module App.special_dtml, line 174, in _exec Module DocumentTemplate.DT_Util, line 201, in eval __traceback_info__: processProperties Module <string>, line 0, in ? NameError: name 'processProperties' is not defined A Very simplified version of my script is here: ## Script (Python) "processProperties" ##bind container=container ##bind context=context ##bind namespace=_ ##bind script=script ##bind subpath=traverse_subpath ##parameters= ##title=Process changes properties for validation before commitment to property sheet ## return 'abcd' I have searched the world over to determine how to 'register/call' my filesystem script from my dtml method with NO LUCK. Can someone please guide me in the right direction? Thanks in advance.
I try to execute the script, processProperties, from inside manage_propertiesForm.dtml. Right now, I am using a simple <dtml-var "processProperties"> call. However, I get a NameError saying that processProperties is not defined. Here is my traceback:
You have to have scripts in the namespace. Do a <dtml-with scripts><dtml-var...></dtml-with>. If you've used the CMF it uses portal skins to mangle the path a bit so they are all on the same "level" -- Andy McKay
Nope that does not work. 'scripts' is a folder on the filesystem that contains my script. I have tried your suggestion and the error is now a KeyError on scripts with the following traceback: Traceback (innermost last): Module ZPublisher.Publish, line 98, in publish Module ZPublisher.mapply, line 88, in mapply Module ZPublisher.Publish, line 39, in call_object Module Shared.DC.Scripts.Bindings, line 252, in __call__ Module Shared.DC.Scripts.Bindings, line 283, in _bindAndExec Module App.special_dtml, line 174, in _exec Module DocumentTemplate.DT_With, line 60, in render KeyError: scripts Andy McKay wrote:
I try to execute the script, processProperties, from inside manage_propertiesForm.dtml. Right now, I am using a simple <dtml-var "processProperties"> call. However, I get a NameError saying that processProperties is not defined. Here is my traceback:
You have to have scripts in the namespace. Do a <dtml-with scripts><dtml-var...></dtml-with>. If you've used the CMF it uses portal skins to mangle the path a bit so they are all on the same "level" -- Andy McKay
Oh sorry I read your email incorrectly I thought you were using a file system directory view from CMF. When you call processProperties from DTML you are calling a method of your product. For DTML or ZPT you use DTMLFile or PageTemplate to import your thing. However with a Python Product, you dont need to make a Python Script object, you are already in Python. Why not just import it directly in Python? There isnt really a mechanism for doing as you suggest, it doesnt really make too much sense. <tangent>Unless your object is folderish in which case you might want to manually add a Python Script to the ZODB in your product.</tangent> Anyway you could make an __init__.py in scripts and then do ... then make a method of your object that uses it so from scripts import processProperties class whatever: somesecurity.declaration() def somefun(self...): processProperties(..) You can then call somefun from DTML and you get properties function.... Hope that makes sense. -- Andy McKay
participants (2)
-
Andy McKay -
Stacy Roberts Ladnier