Newbie questions: Calling PageTemplates from Python, and getting meta-info on ZSQL method results
Hi, I've got a couple of newbie-questions. 1. I want to call a PageTemplate from a Python script, and pass in parameters. How can I access those parameters in the PageTemplate? 2. How can I find out the fields which are in the resultset of a ZSQL method, using either Python or PageTemplates? I do: SELECT * FROM employees. I know that the table employees contains the fields emp_id, first, last, salary so I can code for it. But it would be nices and more generic if I could infer from the resultset itself what fields it has, and to extract them dynamically instead of coded into the PageTemplate. That way I could make a generic PageTemplate that works for any ZSQL method result. 3. How do I install the MySQLdb driver on Win2k? The installer only finds my Python21 installation, and not my Zope installation and it doesn't give me the option to enter a directory manually. I don't have MSVC++ compilers installed, only gcc from cygwin, so I don't think that compiling it myself will work. Any hints from anyone? With thanks, --Tim
Leeuw van der, Tim wrote:
2. How can I find out the fields which are in the resultset of a ZSQL method, using either Python or PageTemplates?
hi, have a look at http://www.zope.org/Members/spinwing/ZSQL_Results cheers, maik -- Maik Jablonski __o www.zfl.uni-bielefeld.de _ \<_ Deutsche Zope User Group Bielefeld, Germany (_)/(_) www.dzug.org
see the (excellent) ZPT tutorial at http://www.zope.org/Wikis/DevSite/Projects/ZPT/TutorialPart3 see the section titled "Other Builtin Variables" jens On Thursday, August 8, 2002, at 09:45 , Leeuw van der, Tim wrote:
Hi,
I've got a couple of newbie-questions.
1. I want to call a PageTemplate from a Python script, and pass in parameters. How can I access those parameters in the PageTemplate?
2. How can I find out the fields which are in the resultset of a ZSQL method, using either Python or PageTemplates?
I do: SELECT * FROM employees. I know that the table employees contains the fields emp_id, first, last, salary so I can code for it. But it would be nices and more generic if I could infer from the resultset itself what fields it has, and to extract them dynamically instead of coded into the PageTemplate. That way I could make a generic PageTemplate that works for any ZSQL method result.
3. How do I install the MySQLdb driver on Win2k? The installer only finds my Python21 installation, and not my Zope installation and it doesn't give me the option to enter a directory manually. I don't have MSVC++ compilers installed, only gcc from cygwin, so I don't think that compiling it myself will work. Any hints from anyone?
With thanks,
--Tim
_______________________________________________ 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 )
re: the ZSQL question... ZSQL methods return a Results object, there's a nice how-to at: http://www.zope.org/Members/spinwing/ZSQL_Results hope this helps, Ben Leeuw van der, Tim wrote:
Hi,
I've got a couple of newbie-questions.
1. I want to call a PageTemplate from a Python script, and pass in parameters. How can I access those parameters in the PageTemplate?
2. How can I find out the fields which are in the resultset of a ZSQL method, using either Python or PageTemplates?
I do: SELECT * FROM employees. I know that the table employees contains the fields emp_id, first, last, salary so I can code for it. But it would be nices and more generic if I could infer from the resultset itself what fields it has, and to extract them dynamically instead of coded into the PageTemplate. That way I could make a generic PageTemplate that works for any ZSQL method result.
3. How do I install the MySQLdb driver on Win2k? The installer only finds my Python21 installation, and not my Zope installation and it doesn't give me the option to enter a directory manually. I don't have MSVC++ compilers installed, only gcc from cygwin, so I don't think that compiling it myself will work. Any hints from anyone?
With thanks,
--Tim
_______________________________________________ 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 )
Hi Tim, On Thu, 8 Aug 2002 08:45:31 -0500 "Leeuw van der, Tim" <tim.leeuwvander@nl.unisys.com> wrote:
Hi,
I've got a couple of newbie-questions.
1. I want to call a PageTemplate from a Python script, and pass in parameters. How can I access those parameters in the PageTemplate?
Parameters are passed to PageTemplates as keyword arguments and are availalbe in the template via the built-in options variable. Call the page template from your python script: return context.somePageTemplate(some_parameter = 'stuff', some_other_parameter='more stuff') And from the page template <span tal:replace="options/some_parameter"></span> <span tal:replace="options/some_other_parameter"></span> You can pass Page Templates extra information with keyword arguments. Check out the chapter on Advanced Page Templates in the Zope Book. It's helpful.
2. How can I find out the fields which are in the resultset of a ZSQL method, using either Python or PageTemplates?
I do: SELECT * FROM employees. I know that the table employees contains the fields emp_id, first, last, salary so I can code for it. But it would be nices and more generic if I could infer from the resultset itself what fields it has, and to extract them dynamically instead of coded into the PageTemplate. That way I could make a generic PageTemplate that works for any ZSQL method result.
In your python script (where selectEmployees is your ZSQL method) use: result = context.selectEmployees() column_names = result.names() which will give you an array of the column names from your query result.
3. How do I install the MySQLdb driver on Win2k? The installer only finds my Python21 installation, and not my Zope installation and it doesn't give me the option to enter a directory manually. I don't have MSVC++ compilers installed, only gcc from cygwin, so I don't think that compiling it myself will work. Any hints from anyone?
Sorry, can't help here.
With thanks,
--Tim
Regards, Jim
participants (5)
-
Ben Avery -
Jens Vagelpohl -
Jim Gallacher -
Leeuw van der, Tim -
Maik Jablonski