How can i call a pyhton module's function from with in Page Temmplates?
Hello, i saw that from within a DTML Method one is able to call a fuction of a python module in the file system. Now i want to get the funtion's results from within a Page Template. Is the right way to make a Script(Python) that calls this module's function and then call this Script(Python) from within my Page Template? Is there any other less nifty way to do this? Thanks in advance. ___________________________________________________________ Χρησιμοποιείτε Yahoo!; Βαρεθήκατε τα ενοχλητικά μηνύματα (spam); Το Yahoo! Mail διαθέτει την καλύτερη δυνατή προστασία κατά των ενοχλητικών μηνυμάτων http://login.yahoo.com/config/mail?.intl=gr
If you already know DTML but need to learn ZPTs I suggest you have a look at this old document http://www.zope.org/Members/peterbe/DTML2ZPT 2005/10/12, Thomas Apostolou <tomatbiz-tominfo@yahoo.co.uk>:
Hello,
i saw that from within a DTML Method one is able to call a fuction of a python module in the file system.
Now i want to get the funtion's results from within a Page Template. Is the right way to make a Script(Python) that calls this module's function and then call this Script(Python) from within my Page Template? Is there any other less nifty way to do this?
Thanks in advance.
___________________________________________________________ Χρησιμοποιείτε Yahoo!; Βαρεθήκατε τα ενοχλητικά μηνύματα (spam); Το Yahoo! Mail διαθέτει την καλύτερη δυνατή προστασία κατά των ενοχλητικών μηνυμάτων http://login.yahoo.com/config/mail?.intl=gr
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
-- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com
Thomas Apostolou wrote:
i saw that from within a DTML Method one is able to call a fuction of a python module in the file system.
I don't think so...
Now i want to get the funtion's results from within a Page Template.
Which function? Give us an example of what you've tried...
Is the right way to make a Script(Python) that calls this module's function and then call this Script(Python) from within my Page Template?
You should be able to make the call direct from the ZPT, but you'll have to tell us what you're trying to do... cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk
Αρχικό μήνυμα από Chris Withers <chris@simplistix.co.uk>:
Thomas Apostolou wrote:
i saw that from within a DTML Method one is able to call a fuction of a python module in the file system.
I don't think so...
Well, you are right. I do not directly call the modules's function from the file system. I call an External Method that "wraps" the module's function and then i call that External Method from my DTML Method. Here is the example: <dtml-in expr="GetData(sysDSN=sysDSN, usr=usr, mypass=mypass, sTable=sTable, sFields=sFields)"> <dtml-if sequence-even> <tr class="even"> <dtml-else> <tr class="odd"> </dtml-if> <dtml-in sequence-item> <td><dtml-var sequence-item> </td> </dtml-in> </tr> </dtml-in> GetData is the name of the External Method i call with the parameters of the module's function as you can see.
Now i want to get the funtion's results from within a Page Template.
Which function? Give us an example of what you've tried...
Is the right way to make a Script(Python) that calls this module's function and then call this Script(Python) from within my Page Template?
You should be able to make the call direct from the ZPT, but you'll have to tell us what you're trying to do...
cheers,
Chris
-- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Thomas G. Apostolou Software Engineer Θωμάς Γ. Αποστόλου Μηχανικός Λογισμικού
Thomas G. Apostolou schrieb:
Αρχικό μήνυμα από Chris Withers <chris@simplistix.co.uk>:
Thomas Apostolou wrote:
i saw that from within a DTML Method one is able to call a fuction of a python module in the file system.
I don't think so...
Well, you are right. I do not directly call the modules's function from the file system. I call an External Method that "wraps" the module's function and then i call that External Method from my DTML Method. Here is the example:
<dtml-in expr="GetData(sysDSN=sysDSN, usr=usr, mypass=mypass, sTable=sTable, sFields=sFields)"> <dtml-if sequence-even> <tr class="even"> <dtml-else> <tr class="odd"> </dtml-if> <dtml-in sequence-item> <td><dtml-var sequence-item> </td> </dtml-in> </tr> </dtml-in>
GetData is the name of the External Method i call with the parameters of the module's function as you can see.
Dont do that. Use a Database adaptor instead - any maybe issue the query there if you dont want the ZSQL-Resultset-wrapping. The reason is, ZDAs take care of pooling and so on and you avoid a per thread reconnection.
Thomas G. Apostolou wrote:
<dtml-in expr="GetData(sysDSN=sysDSN, usr=usr, mypass=mypass, sTable=sTable, sFields=sFields)"> <dtml-if sequence-even> <tr class="even"> <dtml-else> <tr class="odd"> </dtml-if> <dtml-in sequence-item> <td><dtml-var sequence-item> </td> </dtml-in> </tr> </dtml-in>
What Tino said about using a database adapter is true, but even if you want to stick with your external method, you can always use the following ZPT: <tr tal:repeat="data python:GetData(sysDSN=sysDSN, usr=usr, mypass=mypass, sTable=sTable, sFields=sFields)" tal:attributes="python:test(path('repeat/data/odd'),'odd','even')" <td tal:repeat="cell data" tal:content="cell"> </td> </tr> You only need to figure out where sysDSN, usr, mypass, sTable and sFields come from. Your example being in DTML, I have no idea ;-) cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk
Αρχικό μήνυμα από Chris Withers <chris@simplistix.co.uk>:
Thomas G. Apostolou wrote:
<dtml-in expr="GetData(sysDSN=sysDSN, usr=usr, mypass=mypass, sTable=sTable, sFields=sFields)"> <dtml-if sequence-even> <tr class="even"> <dtml-else> <tr class="odd"> </dtml-if> <dtml-in sequence-item> <td><dtml-var sequence-item> </td> </dtml-in> </tr> </dtml-in>
What Tino said about using a database adapter is true, but even if you want to stick with your external method, you can always use the following ZPT:
<tr tal:repeat="data python:GetData(sysDSN=sysDSN, usr=usr, mypass=mypass, sTable=sTable, sFields=sFields)"
tal:attributes="python:test(path('repeat/data/odd'),'odd','even')" <td tal:repeat="cell data" tal:content="cell"> </td> </tr>
You only need to figure out where sysDSN, usr, mypass, sTable and sFields come from. Your example being in DTML, I have no idea ;-)
sysDSN, usr, mypass are properties with values of a folder object witch i use with aquisition to call the DTML Method trough it. sTable and sFields are input fields of the form that calls the DTML Method and submits its values Thomas G. Apostolou Software Engineer Θωμάς Γ. Αποστόλου Μηχανικός Λογισμικού
participants (5)
-
Chris Withers -
Peter Bengtsson -
Thomas Apostolou -
Thomas G. Apostolou -
Tino Wildenhain