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.
People who come to your site want a personal relationship with Elvis. You can provide this by tailoring your site to the needs and preferences of your viewers. Let's add the ability to bring new Elvis sightings to the attention of site visitors. This way when a visitor comes to your site they'll immediately know which sightings are new since they last visited.sightings.html
template to edit it.Test
tab to view it.All the sightings should be marked as new.
Now none of the sightings should be marked as new. This is because you've already seen them.
sightingsFolder
folder to enter it.File
from the "Select type to add..." list.Seattle
for the id. Add
button.<p>6/1/2003 -- Seattle</p> <p>Elvis spotted spare changing on Broadway. He denied being the King.</p>
Save Changes
button.Now you've created a new sighting. Let's see if it is marked as new by the sightings page.
sightings.html
page in the lesson9
folder.Test
tab.Sure enough our new sighting is marked new.
How does this work? It uses HTTP Cookies. When you visit the
sightings.html
page a cookie is set that records the current
time. Then each time you return to the page sightings that are newer
than the cookie will be marked as new.
Let's look at how this works.
sightings.html
template to view its contents.Notice that the page uses the tal:define statement to defines a
lastVisit
variable. It is defined by calling the lastVisit.py
script. This variable holds the time that the user last visited the
page as recorded in a cookie.
Later in the template this time is compared to the modification time
of each sighting object. If the sighting is new then it is marked as
such by including a bold tag. The bold tag uses the tal:condition
statement to optionally include its contents. In this case the
condition checks to see whether the bobobase_modification_date
of
the sighting is newer than the last visit. This strangely named
method keeps track of the last modification date of Zope objects.
Now let's examine the
lastVisit.py
script.
lastVisit.py
script to view it.Notice how it includes comments explaining its functioning. Comments begin with a number sign. The script does two things: it retrieves a cookie from the request, and it sets a new cookie using the response.
You can use cookies to personalize a web page. Zope templates can dynamically control their presentation.
setCookie
method.bobobase_modification_date
method returns the last
modification time of an object.In the next lesson you'll learn how to create a mail feedback form.