Home | Trees | Index | Help |
|
---|
Package aquarium :: Package screen :: Module ScreenAPI |
|
Document the API for screen classes.
Screens are the focal point of interaction with the user. In general, the URL controls which screen is shown. There are two types of screens: controllers and views. Controllers contain business logic and are written in Python. Views contain display logic and are written in Cheetah.
Controllers are responsible for:
As a last note, controllers are free to subclass any other subclass of aquarium.util.AquariumClass they want. However, it is common to first create a subclass of aquarium.screen.Controller and then make all of your controllers subclass that class.
Views are responsible for displaying content. Views encapsulate the main content returned as a result of some request. Views subclass layout classes. For instance, if the main content of a Web site is always in the middle, with navigation buttons along the top, each view in the Web site would subclass a layout named TopNav. Sometimes views are used to generate non-HTML content, such as an XML report. In such cases, it is customary to subclass the layout aquarium.layout.Bare.
Views that have a __call__ method that receives arguments (other than self) are not directly accessible from the outside. Trying to use a Web browser to request such a view directly will result in an exception. (When the layout tries to call the view's __call__ method without any arguments, a TypeError exception will occur.) This type checking is by design. Having Python enforce the API between the controller and the next screen is a real strength of Aquarium in contrast to JSP style forwards.
The astute reader may wonder, "If I have view and controller, where is the model?" Aquarium enforces the use of controllers and views, but the distinction between controller and model is entirely up to the developer/application. You can make the controllers as "thin" or "heavy" as you wish.
Controllers and views are stored in the same directory because experience shows that if you're working on one, you'll probably want to work on the other. The modus operandi is to have a directory hierarchy that matches the hierarchy found in the URLs for the Web site. Within each directory views and controllers sit side by side.
Controllers and views have the same API in that both must implement a __call__ method:
Return the contents of this screen as a string or do a forward.
To support streaming very large or infinite amounts of data, instead of returning a string, __call__ may be a generator or return a generator. Note, however, that you can't easily do this in Cheetah because every Cheetah method implicitly does a return. See the echo screen for an easy way to use this feature.
Home | Trees | Index | Help |
|
---|
Generated by Epydoc 2.1 on Mon Jan 1 16:34:19 2007 | http://epydoc.sf.net |