This financial calculator was my first experience with TurboGears and AJAX, and I'd like to share this experience by writing a tutorial. I expect it is useful for TurboGears beginners as myself, and perhaps for people wanting to calculate a mortgage :)
In principle, a calculator is best implemented without AJAX. It is much more efficient to make all calculations at client sie, as my Java and Javascript calculators already do.
The calculator was my guinea pig since I already had the Javascript version, which saved me from create the HTML page as well as the financial formulas. The intention was really to lose the virginity on AJAX: see the request go and return with a result.
To be fair, I still take AJAX with a grain of salt. My biggest concern about it, is that it forces one to employ at least 4 different tools: (X)HTML, CSS, Javascript, and a language+framework in the server-side -- Python+Turbogears in this tutorial. My second major concern is the more difficult debugging in client-side code (HTML, CSS and Javascript debugging).
Anyway, AJAX is the biggest hype these days, so we need to deal with it. And it may be extremely fun to deal with evolving (and immature) technologies.
TurboGears is a collection of Python software, aimed to Web development, offering a complete top-to-down framework, from database access to interoperable Javascript. The main TG components are:
People with more experience in GUI and object-oriented development will recognize the MVC (Model-View-Controller) in TurboGears. Kid supplies the View, CherryPy supplies the Controller and SqlObject supplies the Model. However, in practice this model can "leak": depending on the page, generate HTML directly in CherryPy may make more sense than try to fit it in the Kid template system.
Once built, your site can be deployed using TG's own server, or employing Apache with mod_python. In either way, a Python interpreter is necessary. It is important to take this into account when you buy a hosting service, since most hostings offer only PHP by default.
We employed the 0.9a6 versions of TurboGears in this tutorial. In order to install TurboGears, follow this instructions.
Next: Creating our project >>>