Log In
Or create an account ->
Imperial Library
Home
About
News
Upload
Forum
Help
Login/SignUp
Index
Copyright
Dedication
Praise for Rapid Web Applications with TurboGears
Prentice Hall Open Source Software Development Series
Preface
Acknowledgments
TurboGears Fundamentals
Introduction to TurboGears
Why TurboGears?
Making Easy Things Easy
Making It Easy to Maintain
The History of TurboGears
TurboGears, Ajax, and Web 2.0
Why TurboGears Values Being “Pythonic�
What Can You Do with TurboGears?
Coming Soon to a TurboGears Near You
Summary
Getting Started with TurboGears
Installing TurboGears and SQLite
Creating a Hello World Application
Say Hi! (Simple Template)
Custom Greetings (Hello from the Controller)
Summary
The Architecture of a TurboGears Application
What Is MVC?
Design Patterns and Object-Oriented MVC
Understanding SQLObject and TurboGears Models
Understanding CherryPy and TurboGears Controllers
Understanding Kid and TurboGears Views
MVC Meets Ajax
Summary
Building a Simple TurboGears Application
Creating a Simple Application
Building a Simple Bookmark Collection Site
Testing TurboGears Applications
A Simple Form to Add Bookmark
Summary
Enhancing Our Bookmark Application
Updating Our Model
Listing by Category
Updating Our Form
Tying Everything Together
Selecting Categories
Summary
Exploring a Real World TurboGears Application
Exploring More Complex Models in WhatWhat Status
What Is WhatWhat Status?
Logging in and Using WhatWhat Status
Exploring the WhatWhat Status Model
Writing Better Model Classes
Keep All Model Logic in Model Methods
Create New Classes to Encapsulate Complex Relational Logic
Summary
Controllers, Views, and JavaScript in the WhatWhat Status
Dashboard Controller
WhatWhat Security and Identity
Exploring the Dashboard Index
Dashboard Templates
Adding a New Project
Dashboard Controller new_project
Summary
RSS, Cookies, and Dynamic Views in WhatWhat Status
Cookies and RecentChanges
The Recent Changes Template
WhatWhat Status Widgets
Easy RSS with FeedController
Summary
Ajax and WhatWhat Status Projects
Handling Ajax Requests
Ajax Requests/HTML Responses
Ajax Requests/JSON Responses
Ajax and XML Responses
Digging Into the Project Controller Methods
A First Look at project.kid
Laying the Groundwork for Our Project Page
Using Ajax to Update Project Status and Descriptions
Summary
SQLObject and TurboGears Models
SQLObject Basics
ORM Basics
Who Needs ORM?
ORM Alternatives
ORM Negatives
Basic SQLObject Features
Basic Connection Management
Automatic DB Schema Creation from SQLObject-Derived Classes
Fine Control on Behavior Using Metadata Class
Automatic Table Description from Existing DB Schema
Simple Database Queries
Getting a Single Object by ID
Getting an Entire Table
Selecting Rows by Column Values
Summary
Mastering SQLObject
Mapping Relationships
One-to-Many Relationships (MultipleJoin)
Many-to-Many Relationships (RelatedJoin)
Straight SQL Queries
Smart Queries
sqlbuilder-Based Queries
Selecting from Multiple Tables
Joins
Nested Queries
Working with Large Result Sets
Don’t list() a Large Result Set. Use Slices.
Don’t Objectify a Large Result Set. Go with Straight SQL.
Apply the Same Method to Bulk Inserts, Updates, or Deletes
Don’t Go to the DB Multiple Times for the Same Objects
Summary
Customizing SQLObject Behavior
Customizing SQLObject Classes with sqlmeta
Inside the sqlmeta cless
Columns, Indexes, and Joins
Name Acrobatics
Lazy Updates and Caching
Expired Rows
Default Order
More-Advanced SQLObject Customization
Adding Magic Attributes
Overriding Attribute Access
SQLObject and Inheritance
Python Objects, Inheritance, and Composition
Composition vs. Inheritance in Standard Python
SQLObject Composition vs. Inheritance
SQLObject and Transactions
Transactions and Connections
sqlhub and Transactions
Encapsulating Transactions Using a Wrapper Function
Encapsulating Transactions Using a Decorator
Summary
TurboGears View Technologies
Dynamic Templates with Kid
Creating Dynamic Templates with Kid
Python-Powered Processing Directives
Content-Producing Expressions
Control Structures
Kid’s Built-In Functions
Beyond the Basics: Keeping Your Templates DRY (Don’t Repeat Yourself)
Transformations Using py:match
Creating Custom Tags with py:match
Creating Parent Templates with py:extends
Bringing It All Together
Summary
Creating Better JavaScript with MochiKit
How to Use This Chapter
MochiKit’s Packaging
MochiKit’s Interactive Shell
Introduction to MochiKit and Its Interactive Shell
Base Functions
The Comparison Problem
More-Complicated Comparisons
A Word about Objects in JavaScript
JavaScript and Python: Not So Different After All
Object Representation
JSON Serialization
Working with Arrays
Pythonic Version of this
Help with Calling Functions
Dictionary-Like Objects
Working with Query Strings
Functions in MochiKit.Base
Iterators in JavaScript
Making an Iterator
Functions from Itertools
Functions Unique to MochiKit.Iter
The Document Object Model
Retrieving Elements
Working with Style
Creating DOM Nodes
Simple Events
Other DOM Functions
Using MochiKit.Logging to Debug
Using Logging
Extended Logging
Simple Logging Demo
Working with Color
The Demo
More Ways to Get a Color
Converting Colors
Modifying Colors
String Conversions and Value Formatting
Working with Dates and Times
Formatting Numbers
Other String Formatting Functions
Summary
Effective Ajax with MochiKit
Handling Asynchronous Events—Including Ajax Requests
Dealing with Results That Arrive Later
Making a Request
Handling Errors
Passing Parameters
Limitations of Ajax
Using JSON
Working with Timers
Canceling Deferreds
Ajax, Timers, and Cancellation Combined
More about Callbacks
Handling JavaScript Events with MochiKit.Signal
Getting Started with MochiKit.Signal
Connecting and Disconnecting
Using MochiKit’s Cross-Browser Event Objects
Custom Events
Visual Effects for That “Wow Factor�
Rounded Corners
Getting Started with Effects
Effect Options
The Core Effects
Combination Effects
Customizing Effect Behavior
An Effects Demo
Sortables and DragAndDrop
Summary
TurboGears Widgets: Bringing CSS, XHTML, and JavaScript Together in Reusable Components
Understanding Widgets
Instantiation Time Customizations
Render Time Attribute Assignment
Using Callables with Widgets
Form Widgets
Custom Form Layout
Form Field Widgets
Compound Widgets
Widgets and Validation
How FormEncode Validators Integrate into Form Widgets
More Validators
Basics of Schema Validation
CSS, JavaScript, and Widgets
Creating Custom Widgets
Anatomy of an Ajax Widget
Summary
CherryPy and TurboGears Controller Technologies
CherryPy and TurboGears Decorators
CherryPy URL Parsing
CherryPy and the HTTP Request/Response Cycle
CherryPy Filters
Input Filters
Output Filters
Creating Your Own Filters
CherryPy and TurboGears Configuration
Decorators
expose()
validate()
Error and Exception Handling
Validation Errors
Multiple Handlers
Exception Handling
RESTful Resources in TurboGears
Summary
TurboGears Deployment
Choosing Your Production Environment
Operating System of the Server(s): Linux, Mac OS, Windows?
Should I Run CherryPy behind Another Web Server?
The Basics of Configuring TurboGears for Production
Using mod_rewrite or mod_proxy to Connect to CherryPy
Advantages/Drawbacks of Using a Proxy in front of CherryPy
Configuring Apache with mod_rewrite
Configuring Apache to Serve Static Content Directly
Configuring CherryPy to Run Behind a Web Server
Making Sure That CherryPy Stays Up
Running CherryPy on mod_python
Advantages/Drawbacks of Using mod_python
Configuring Apache/CherryPy for mod_python
Other Ways of Running CherryPy behind a Web Server
Scalability of Your Site
Scaling Sessions
Scaling Your Application
Scaling at a Lower Cost
Summary
TurboGears Extras
The TurboGears Toolbox and Other Tools
Toolbox Overview
ModelDesigner
CatWalk
WebConsole
Widget Browser
Admi18n and System Info
The tg-admin Command
Other TurboGears Tools
Summary
Internationalization
Dealing with Unicode in Python
Dealing with Unicode in TurboGears
SQLObject and Unicode
Kid Templates
Unicode in CherryPy’s Request/Response Cycle
Translating Your Application
Localization of Python Sources
Localization of Kid Templates
Auto-Detect User Language Preference
Locale-Specific Objects
Admin i18n Interface
Toolbox admi18n Tool
tg-admin i18n Command-line Tool
Summary
Testing a TurboGears Application
Nose
TurboGears testutil
Mechanize
Selenium
Summary
TurboGears Identity and Security
Basic Authentication/Authorization with Identity
Validating User Access with Identity
Avoiding Common Security Pitfalls
Summary
Appendix
SQLAlchemy
A Quick Tour of SQLAlchemy
SQLAlchemy in TurboGears
Data Mapper and Active Record
More about ActiveMapper
How Objects Are Cached in SQLAlchemy
Should I Use SQLAlchemy or SQLObject?
Migrating a Project to SQLAlchemy
Deployment Configuration
Application Configuration
Class Definitions
Changing Calls to byName Methods
Updating Queries
Final Thoughts
← Prev
Back
Next →
← Prev
Back
Next →