Source Code

As you work through the examples in this book, you may choose either to type in all the code manually or to use the source code files that accompany the book. All of the source code used in this book is available for download at www.wrox.com. When you get to the site, simply locate the book's title either by using the Search box or by using one of the title lists and click the Download Code link on the book's detail page to obtain all the source code for the book. Because many books have...

Professional Python Frameworks Web Programming Django and TurboGears

10475 Crosspoint Boulevard Indianapolis, IN 46256 www.wiley.com Copyright 2007 by Wiley Publishing, Inc., Indianapolis, Indiana Manufactured in the United States of America Library of Congress Cataloging-in-Publication Data Moore, Dana, 1947- Professional Python frameworks Web 2.0 programming with Django and Turbogears Dana Moore, Raymond Budd, William Wright. p. cm. Includes index. ISBN 978-0-470-13809-0 pbk. 1. Web site development. 2. Python Computer program language I. Budd, Raymond, 1976-...

Initializing the Database with the Interactive Shell

As noted in the previous section, you could use the execute command to load the database from the command line, but TurboGears also provides an interactive shell that makes this much simpler. To start the shell, invoke the tg-admin command from the base project directory again, this time providing the shell subcommand as follows shell This starts an interactive Python shell, initialized to the configuration of your project. It gives you access to all your model classes, as well as any other...

Defining the Search View in the Controller

At this point, the view is finished. Each time the user selects a different pet owner, an asynchronous call will be made to http localhost 8080 search with the selected owner ID. The only step that remains is to define the path, search, and have it return the list of pets for a given owner ID. To do this, add the following new method to controllers.py pets entry.name for entry in Pet.select Pet.q.ownerID owner log.info Got the pets for owner owner str pets return dict pets pets 1. It takes the...

Listing PetsExamplejs XML Parsing Functions

45 var parser new DOMImplementation 46 var domDoc parser.loadXML xml 47 get the root node in this case, it is petowner 48 var docRoot domDoc.getDocumentElement ERROR Pets retrieved for 63 petname pet.getFirstChild .getNodeValue petname 69 end function parseQueryResult 71 function parseStoreResult xml 72 var parser new DOMImplementation 73 var domDoc parser.loadXML xml 74 var docRoot domDoc.getDocumentElement ERROR Pets stored for 88 petname pet.getFirstChild .getNodeValue 94 end function...

Initializing the Database with CatWalk

Another alternative to interacting with your model objects via the interactive shell is to use CatWalk, a web-based model administration tool that can be used to manage the data in the database. You can access CatWalk using the toolbox subcommand of tg-admin, a web-based project administration tool. First, start the TurboGears Toolbox from the base project directory as shown here toolbox This displays the web page shown in Figure 3-3. It includes CatWalk and a variety of other utilities that...

MVC Architecture in Django

Although Django uses the MVC architecture, the developers have a slightly different interpretation of the MVC concept when compared to TurboGears and most other web frameworks. Unfortunately, this can cause a lot of confusion when a developer initially investigates different frameworks, but ultimately the capabilities are quite similar. In Django the distinctions between the three main components exist as they do in other frameworks, but the names and responsibilities of each component are a...

Listing Example XML Response

lt xml version '1.0' encoding 'ISO-8859-1' gt lt petowner gt lt lastname gt Wright lt lastname gt lt pet gt Fluffy lt pet gt lt pet gt Poochie lt pet gt lt petowner gt This document contains lt petowner gt as its root element. Inside that element are one lt firstname gt element, one lt lastname gt element, and zero or more lt pet gt elements. The server returns the same document for search and save operations. Simple is good. If there is any kind of error, the document in Listing 2-9 is...