[Zope] How to pass arbitrary objects to a ZPT from Script(Python)

Martin Diers martin at diers.us
Sat Nov 8 12:48:39 EST 2003


I am programming a purchase order system, using MySQL as a backend.

I am new to Zope, but have much experience in RDBMS, some ASP.NET, etc. Currently firmly
entrenched in Linux.

I am attempting to develop a standard methodology for accessing my databases. I have created ZSQL
methods for searching/insert/delete/update. I am using ZPT's.

I have a single Script(Python) which processes data requests using an if,elif tree. The idea is
simple: all data submit buttons are named btnDataCommand. The value of the button determines which
action the script performs. Record ID's are passed via hidden form fields.

I would ideally like to have this single python script perform all ZSQL method calls. To me it
just makes sense to have all your update logic in a single script. Right now I perform inserts,
deletes, and updates directly in this script. However, when it comes to fetching data and
displaying it in a ZPT, I have hit a brick wall. Right now I am passing the ZPT a record ID, and
having the ZPT call the ZSQL method to retrieve its own data.

Example:

    elif datacommand == "Edit":
        vendorID = request.get("vendor_id")
        page = context.addeditVendor_html(record=vendorID)
        return page

I would prefer something like this:

    elif datacommand == "Edit":
        vendorID = request.get("vendor_id")
        results = searchVendors_sql(VendID=vendorID)
        page = context.addeditVendor_html(dataset=results)
        return page


My problem is this: How can I, from a python script, pass a result set which has been returned
from a ZSQL method, on to a ZPT, so that I do not have to call the ZSQL method within the ZPT file
which is displaying the data? I tried passing the result set as an option to the ZPT, but it shows
up empty in the ZPT. The options container is not well documented, but apparently it is a simple
tuple, and will not allow you to put an arbitrary object in the "value" side.



More information about the Zope mailing list