Lesson 8. Elvis Photo Archive, cont.

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.

Now that we have a working photo archive, let's enhance it to handle submissions from site visitors.
  1. Click the form.html template.
  2. Click the Test tab to view it.
  3. Upload a picture (JPG, GIF, PNG or other graphics format supported by your browser.)
  4. Now return to the lesson8 folder in the Zope management screen using your browser's back button.
  5. Click the photoArchive folder to enter it.

Notice that there is now a new Image object in the folder. This image was created when you uploaded your photo.

Let's investigate how this works, and add the ability to give our uploaded photo a title.

  1. Click the form.html template.
  2. Change the contents to:
    <html>
    
    <h1 tal:content="template/title">title</h1>
    
    <p>Upload a picture to the Elvis Photo Archive.</p>
    
    <form action="action.py" method="post"
    enctype="multipart/form-data">
    <p>File: <input type="file" name="file"></p>
    <p>Title: <input type="text" name="title"></p>
    <input type="submit">
    </form>
    
    </html>
  3. Click the Save Changes button.

This page collects data needed to create an Image. It calls the action.py script with that data. The action.py script actually creates the Image. Now let's customize the script to handle the image title.

  1. Click the action.py script to edit it.
  2. Change the parameter list to file, title.
  3. Change the contents of the script to:
    """
    Create a new image in the photo archive folder.
    Then return a confirmation page.
    """
    folder=container['photoArchive']
    folder.manage_addImage(id='', file=file, title=title)
    page=container['thanks.html']
    return page()

The script collects the form data, creates an image object in a folder and then returns a thanks page. It gets access to form data through its parameters. It calls the manage_addImage folder method on the photo archive folder to create a new image there. Finally it locates the thanks page and renders and returns it.

Summary

In the next lesson you'll learn about HTTP Cookies and personalizing your web site.