TurboTunes tutorial

by Ronald Jaramillo

watch

This tutorial is also available as a screencast.

Download it here:

Having trouble? Check out the video help page.

Stealing Apple's market share with TurboGears

${nvtitle()} This tutorial uses features that are not in the current release.

This is the text version of the "TurboTunes" video (19.3 MB QuickTime) by Kevin Dangoor. The video is also available in the Internet Archive and via BitTorrent.

This tutorial will show you how to implement your own music store using TurboGears.
To give you and idea of what we plan to achieve check this short clip.


We will cover the following steps:


Create new project

Start by creating a new TurboGears project using tg-admin quickstart. Call your project TurboTunes.

tg-admin quickstart

Configure your database

Create a database for your project, and configure your dev.cfg and prod.cfg to match your database settings. I'm using postgres and things look like this for me:

Implementing your model

Open your model file (model.py) and start defining your model classes.
We want to group our artist by genre:

We define a many to many relation to our artist object which looks like this:

Artists make albums, so we define a new object:

And finally the music

Run tg-admin sql create and the tables will be created for you.

tg-admin sql create

If you want to follow along (or don't feel like typing) download the model file here

Mount CatWalk

Open your controllers.py file and 'mount' CatWalk like this: Remember to import your model and pass it to CatWalk as a parameter

Start your webserver:

python turboTunes-start.py

CatWalk should be up an running on http://localhost:8080/catwalk

Populate your Store

You can use to CatWalk to quickly populate your store. Start by adding genres, then add some artist. Configure wich genres an artist belongs to. Add albums to your artists and song to your albums...
Somewhat like
in this clip


Write your controllers

Your controller will implement the following methods:

The complete controller file (controllers.py) looks like this:

Still don't fell like typing? Download the controller file here

Edit your template

The TurboTunes Music Store is composed of three select boxes and a grid view. The first box list the genres, the second the artist and the third the albums. The grid view, displays the songs.

Your template (templates/tunes.kid) should import MochiKit and Widgets (which CatWalk user for rendering it's interface). You still have to write some functions to pull all the bits together.

This is your project largest file:

Get it here

Recap

That's it! You are almost ready to dress yourself in a black turtleneck and reveal just one more thing for your devotees.
Of course people should be able to buy your music, hear a small sample, and see he album artwork, but that's left as homework

Download the zipped project files here