[Zope] Newbie questions: Calling PageTemplates from Python, and getting meta-info on ZSQL method results

Jim Gallacher jgallach@albedo.net
Thu, 8 Aug 2002 11:34:03 -0400


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