by Ronald Jaramillo
This tutorial is also available as a screencast.
Download it here:
Having trouble? Check out the video help page.
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:
Start by creating a new TurboGears project using tg-admin quickstart. Call your project TurboTunes.
tg-admin quickstart
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:
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
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
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
Your controller will implement the following methods:
Serves the main html template
Builds and return a list of genres
Builds and return a list of artist belonging to the requested genre
Builds and return a list of albums belonging to the requested artist
Builds and return a list of songs belonging to the requested album
Still don't fell like typing? Download the controller file here
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.
Should be called by your body 'onload' function. It load the genres list and initialize the grid
Ajax request to your genres method. Sets a callback to loadList
Pass a JSON data structure on Widget.select.load wich populate the selects boxes
Ajax request to your artists method, passing the selected genre as a paramater
Ajax request to your albums method, passing the selected artist as a paramater
Ajax request to your songs method, passing the selected album as a paramater
Calls Widget.grid.render passing a JSON data structure.
This is your project largest file:
Get it here
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