Woven Links: The Program of your Tutorial

Motivation

I wrote this program because Mozilla kept losing my bookmarks, and i got tired of coding the html in my ~/public_html/index.html by hand every time I wanted to add a link to something. I'd been programming in Python for about two years, and hanging out in #python on freenode.net, and when someone suggested using Woven, it seemed like a natural and easy way of creating dynamic web content.

The program we'll be looking at is a bookmark organizer. It organizes the bookmarks into categories, each category with a descriptive heading, and presents them in a table. The program makes use of a two panel design, with a consistent, left-hand-side menu for site navigation.

I turned it into this tutorial both to give something back to the developers, and because Woven's users seem to be having similar problems to those that I had while writing this application. One thing that struck me was that the HowTos are all very well written and informative, but sometimes I found it difficult to fit all of the pieces together. I hope to be able to weave (no pun intended) a narrative context around the relevant documentation that exists already in the Twisted HowTos. I'll do my best to link to appropriate topics throughout this document.

I hope, Dear Reader, that you'll find this tutorial useful.

And now, on with the show...

Running the tutorial

In order to run this tutorial, make sure you have met the prerequisites.

go to xx-- insert file path here --xx and type on the command line:

    $ twistd -noy RunHome2.py

This will start the server, but won't daemonize so you can see the debugging/logging information. Then point your web browser to http://localhost:7000/home. This will put you on the main links page called '/home'.

Overview and Structure

You'll notice on the left there's a menu with choices to allow the user to go to the main page, edit the links, or during development and debugging, reload the application. If you click on the edit link, you'll see the menu remains on the left, and in the center now is a list of all the links on the main page, with options to edit or delete any particular link, or to add a new link. If you click on the rebuild modules link, you'll see a ton of debugging info fly by in the terminal, and you'll wind up back on the main page. What the program has just done is reload all the modules that comprise this application so that changes made in the source code will take effect in the live application being served by twistd (more on this later).

This classes in this application fall into three categories. There are the classes that handle the back-end data directly, there are classes that wrap that data and are used as Woven models, and there is the Woven code itself.

First, we're going to take a look at the application code, the part that runs the TCPService and answers requests. Then we'll take a look at the page responsible for handling the control of program flow. Then we'll look at how the backend supplies the front end with data. And lastly, we'll explore how to do form submittal, and some of the common idioms of Woven.

next prev toc