My first TurboGears project

July 25, 2006

My first TurboGears project will be a web-based GTD application. GTD stands for Getting Things Done, and is a method for managing time and commitment.

Of all my ideas I chose this because of the interesting model, which will consist of one-to-many and many-to-many relations. It also has all kinds of database operations (CRUD).
I also hope to learn some advanced kid templating, since the UI will consist of many panels: header, footer, left, right and middle.

The Model

Main object is the Project, which has Actions (tasks). When all actions are done, the project is complete. Actions belongs to a Context, which describes where this Action can be done (home,computer,phone,work etc).
Actions are usually listed by Context or Project.

Actions also has Tags. They help to find things, and gives me a chance to try out many-to-many relations.

I will add more functionality to the model later, for example a history view of changes.

Here’s a simplified diagram:

starter model
The User Interface

I have used a GTD-application before called d3. It has such a good interface that I will use it as a base for my project.

Advertisements

Model Designer and Catwalk

July 18, 2006

TurboGears comes with a collection of web-based tools bundled into something called Toolbox. I checked out Model Designer and Catwalk.

Toolbox


Model Designer

The Model Designer lets you create your model through a web browser. It also comes with a diagram view of the tables and their relations. It doesn’t tell any details about the type of relations, which would have been great. You can also generate the model source code and the tables.

The problem with the tool is that if you manually change your model, there’s no way to continue using Model Designer, since your real model is out of sync with the state of the tool.

Wouldn’t it be great if it read the meta-data from the database or the model source code so you could continue even if you made a couple of changes by hand?

Model Designer


Catwalk

Catwalk is a great tool for testing your model. It allows you to do CRUD-operations against your database. Very useful. The only glitch I found was that there weren’t any warnings displayed when there was an error during the database operation (for example when I didn’t add anything into a ‘not null’-field). The only way to find this out is to watch the console you started Toolbox from.

Overall the modeling was a joy. You get quick results, and you can experiment without any big hassles.
Catwalk

TurboGears 1.0 will include another great thing called ‘fastdata’. It will automatically create web pages for your model. This will save a lot of time.


Looking for documentation

July 12, 2006

Here’s a list of documentation that helped me getting started with Python and TurboGears:

Python:

A Byte of Python
Python 2.4 Quick Reference

TurboGears:

Official documentation – Preview documentation for 1.0
A request’s journey through the TG stack – Simple and beautiful
The CherryPy Documentation – the web development framework
Kid documentation – template language
SQLObject – object-relational mapper

The TurboGears discussion group isn’t very active. It is rare with more than ten posts new topics per day. The freenode channel #turbogears has about 50 users logged in at 13:00 UTC/GMT +3 hours. The irclog shows that there aren’t very much activity here. 81 lines for one day.

Thanks to Trac it is easy to follow the status of the project and see who is doing what. Trac timeline is a good way to follow the activity of the project.

Conclusion

There is for sure enough documentation for a beginner to get started. I’ve heard complaints that there are too little of it. Compared to many other open source libraries I feel overwhelmed with material. There are also some on-line videos to learn from.

The activity on the forum and the channel were surprisingly low for a project that has so much fuzz. I was hoping for more discussion. You don’t always get an answer either in the channel. Not very nice for a newbie.

There is an upcoming book called Rapid Web Applications with TurboGears.

Using Python to Create Ajax-Powered Sites


Setting up the development environment

July 12, 2006

After looking for a good IDE for a while I decided to go for Pydev. It’s a Python IDE based on the Eclipse platform. I am not a fan of Eclipse for Java development, but since the Python plugin for IDEA seems not to be available for my IDEA version, I have to cope with Pydev.

Fred has all the information needed to set it up. He also shows how to launch TurboGears tools from within Eclipse.


Getting started with TurboGears

July 11, 2006

Actually I did the The 20 Minute Wiki some months ago, so I skipped it even if I’ve forgotten half of it. I decided to begin with Brian’s TurboGears Tutorial.

Requirements

I already had Python 2.4x and EasyInstall installed, so the only thing missing was the latest version of TurboGears. A single line installed the 0.9a6 version:

easy_install -Uf 
http://www.turbogears.org/preview/download/index.html TurboGears

Missing from the tutorial was that docutils (install with easy_install docutils) seems to be required in 0.9. I also installed Python interface to SQLite 3. Can’t be much easier than that.

On with the tutorial

The tutorial consists of building a model, generating database tables from the model, using the built-in interactive shell to add/query data to/from the database, adding some logic to the controller, fiddling with templates and calling the controller from the page. I skipped the AJAX-part for now.

Amongst the things that impresses most with your first TurboGears tutorial is that there are some handy tools that works out of the box, like generating tables from the model and starting the web server. Both single line commands that you just run from inside your project folder. So far the controller or the templates didn’t really enlighten me. Probably because the tutorial was so basic. Mapping between the page and the controller doesn’t at least require any xml-configuration as in most Java web frameworks (some can be replaced with annotations in Java 5), but I don’t yet know if this this is a good thing in a bigger project.

Another nice thing is how easy it is to do for example one-to-many relationships.

Conclusion

Overall, getting started with TurboGears is much easier than with any Java web framework I’ve used. This is not a very kind comparison, since I haven’t used any of the lighter Java web frameworks. Just the most most popular ones (Struts, Webwork2, JSF).

Setting up a JSF project with my favorite IDE IDEA would include automatic generation of a skeleton project and installation of MyFaces. I would manually add Hibernate (or iBatis), a web server, an Ant script for various tasks (like regenerating the database from the model) etc. I guess it might have taken about 4 hours. All this came free with TurboGears. So for a newbie, the initial setup is more than ten times faster with TurboGears I would guess.

Do I like TurboGears yet?

Setting up a project from scratch is still a very small issue compared to developing the product, so I don’t count this as a big advantage.

I am impressed with the out of the box console and how easy it is to define relationships in your model.


Choosing a web framework

July 8, 2006

Read my About page to see what I’m up to.

I’ve been using the major frameworks for Java professionally.

It started with Struts. Then came WebWork. I did something small with Spring Web Flow until I went to a company that made the decision to jump to JSF.

It has been an interesting ride. The biggest annoyances with web development have been:

* It takes too much time. Sometimes a small thing takes days to solve. Most time goes to trial and error weird working tags, xml configurations etc. The server side development is nothing compared to these issues. Searching the web for datatable and commandbutton will give you an example of an issue that has made many guys bald. The development cycle is also slow. You have to restart the web server when you change a JSF configuration. When the application grows, it is frustrating to wait for the server to restart after every minor change.

* You need very experienced developers. .NET-developers in our company seems to get more done even without years of experience. I think this article is partly right.

So I decided to choose Turbogears as the web framework. First because I want to learn Python. Second because Turbogears is a collection of pre-existing projects. I believe these projects must be architecturally in a good shape, since they can be used as modules in Turbogears.

There’s also a lot of fuzz about Turbogears. Not as much as of RoR, but enough to get you interested. The biggest claim is that it is fast to get things done with. Sounds good, but I want proof.

I found some interesting links when researching Turbogears. Bruce Eckel is also trying out Turbogears. Eckel is the author of a book that thought me Java in a great way.