Zope question (while using Plone)
Hello, I am trying to create a page template in the ZMI that functions in the following way: 1) Page contains two entry fields 2) The values from the entry fields become arguments for a ZSQL method 3) The results of executing the ZSQL method are output to the same page, below the initial entry form When I test my page template, I receive a NameError, indicating that name 'start_date' is not defined. I would assume that I need to use dtml tags or define two tal variables, but I am unsure about how to implement them. Here is what I have, so far: ZSQL Method (DBTestQueryMethod): ------------ select FIRST_NAME, LAST_NAME from EMPLOYEES WHERE HIRE_DATE BETWEEN <dtml-sqlvar "start_date" type=string> AND <dtml-sqlvar "end_date" type=string> (I know, I won't get the entire range with this query) ZSQL Method Arguments: ---------------------- start_date, end_date Page Template: -------------- <html> <head> <title tal:content="template/title">The title</title> </head> <body> <h1 id="title" tal:content="template/title">This is where the main heading goes</h1> <form action="output.html" method="get"> Please Enter Start Date: <input type="string" name="start_date" width="30" value=""> Please Enter End Date: <input type="string" name="end_date" width="30" value=""> <input type="SUBMIT" name="SUBMIT" value="OK"> </form> <table border=0> <tr> <th>First Name</th> <th>Last Name</th> </tr> <div tal:repeat="result here/DBTestQueryMethod"> <tr> <td><span tal:replace="result/FIRST_NAME ">FIRST_NAME goes here</span></td> <td><span tal:replace="result/LAST_NAME"> LAST_NAME goes here</span></td> </tr> </div> </table> </body> </html> Page Property ------------- dynamicContent boolean I would be very grateful for any direction you could provide me with. Thanking you in advance, Chris
ZSQL Method Arguments:
----------------------
start_date, end_date
<div tal:repeat="result here/DBTestQueryMethod">
So... where are the arguments? ;) You need something like:
<div tal:repeat="result
python:here.DBTestQueryMethod(start_date='date1', end_date='date2')"> If I can advise, then use three objects: 1. index_html - Script(Python) 2. body - ZPT 3. DBTestQueryMethod - ZSQLMethod index_html may be something like: --------------------------------------- results = [] if request.has_key('start_date'): start_date = request.get('start_date', None) end_date = request.get('end_date', None) results = context.DBTestQueryMethod(start_date=start_date, end_date=end_date) body = context.body return body(results=results) --------------------------------------- and in body use: --------------------------------------- <form action="index_html> (...) </form> <div tal:define="results python: path('options/results|nothing') or []" tal:repeat="row results"> your table </div> --------------------------------------- But where is Plone here?? -- Maciej Wisniowski
One more thing:
ZSQL Method (DBTestQueryMethod):
------------
select
FIRST_NAME, LAST_NAME from EMPLOYEES
WHERE
HIRE_DATE BETWEEN
<dtml-sqlvar "start_date" type=string>
AND
<dtml-sqlvar "end_date" type=string>
Not: <dtml-sqlvar "end_date" type=string> but: <dtml-sqlvar end_date type="string"> -- Maciej Wisniowski
participants (2)
-
Christopher A. Nethery -
Maciej Wisniowski