Zope cannot find the tutorial examples. You should install the tutorial examples before continuing. Choose "Zope Tutorial" from the product add list in the Zope management screen to install the examples.
If you have already installed the tutorial, you can either follow along manually, or reinstall the tutorial examples. Note: make sure that you have cookies turned on in your browser.In the last lesson you created an Elvis sightings database. Now let's adapt the this database to allow site visitors to submit their own sightings.
This lesson builds on your experience from the last two lessons. To allow folks to report sightings you'll need a report form just like you used in lesson 10.
form.htmltemplate to view its contents.
This page is almost exactly like the report form used in Lesson
10. It collects data and calls the
action.py script to
process the data.
action.pyPython Script to view its contents.
It calls the
insertSighting ZSQL Method with this
insert(name=name, location=location, date=date, description=description)
Then it returns a confirmation page.
The real work is done by the
insertSighting ZSQL Method. Let's see how.
insertSightingZSQL Method to view its contents.
The query template contains the following SQL code:
insert into elvis_sightings values( <dtml-sqlvar location type="string">, <dtml-sqlvar date type="string">, <dtml-sqlvar name type="string">, <dtml-sqlvar description type="string"> )
This code inserts a row into the
elvis_sightings table. Notice how
the arguments of this ZSQL Method correspond to the form elements in
You can test this SQL code to make sure it works correctly.
Zope will send the SQL code to the database and will tell you the
SQL code that was sent, and the results that the database
returned. In this case the database will not return anything, since
INSERT command produces no results.
Now return to the
sightings.html page to see if the sample data
was added to the list of sightings. Play with the system a little
bit and see how the links between the
action.py objects allow a visitor to navigate the site.
You can easily change data in a relational database with Zope. The process for inserting data is very similar to the process for querying a database; you use a ZSQL Method in both cases.