More on TurboGears
Leif Oppermann, 24.04.2008
Course of this lecture
• Example project: Movie Collection
• Utilizing movie data
– IMDb
– IMDbPy
• Explaining
– Model
– V...
Source of data: IMDB
• The Internet Movie Database (www.imdb.com) is
an online database of information about movies,
actor...
Getting IMDb data
• IMDb *always* had a data interface
(Zipped text files over FTP server)
• a Python implementation of th...
IMDbPY
• IMDbPY is a Python package useful to
retrieve and manage the data of the IMDb
movie database about both movies an...
Example project: Movie Collection
• Idea: browse movies (with IMDB info) and
store favourites with annotations
• Functiona...
Uses 2 databases
• Database #1: imdb.sqlite
– Self generated from IMDB data
– >11 hours parsing
– ~ 2 GB in one file
• Dat...
Model for database #2
from turbogears.database import PackageHub
from sqlobject import *
hub = PackageHub("imdb01")
__conn...
Templates
• Movielist.kid
• Search.kid
• Browsemovie.kid
• Edit.kid
• Movie.kid
<body>
<div id="status_block">Showing your collection of movies</div>
<div id="sidebar">
Choose a movie or start a search
...
<body>
<div id="status_block">Editing note for: <span py:content="movie.title">move title goes
here</span>
</div>
<div id=...
Search Controller
@expose(template="imdb01.templates.search")
def search(self, searchterm):
i = imdb.IMDb(**IMDB_PARAMS)
#...
Away with Powerpoint
• Let‘s talk about the source!
Thanks for your attention
• Questions / Comments / Get the source:
– Now, or via email: LXO@CS.NOTT.AC.UK
• Blog entry for...
Additional pointers
• Of course there are similar frameworks for other programming languages, the
"original" being Ruby on...
Introduction to Model-View-Controller (MVC) Web Programming with ...
Introduction to Model-View-Controller (MVC) Web Programming with ...
Upcoming SlideShare
Loading in …5
×

Introduction to Model-View-Controller (MVC) Web Programming with ...

845 views

Published on

1 Comment
0 Likes
Statistics
Notes
  • Be the first to like this

No Downloads
Views
Total views
845
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
17
Comments
1
Likes
0
Embeds 0
No embeds

No notes for slide

Introduction to Model-View-Controller (MVC) Web Programming with ...

  1. 1. More on TurboGears Leif Oppermann, 24.04.2008
  2. 2. Course of this lecture • Example project: Movie Collection • Utilizing movie data – IMDb – IMDbPy • Explaining – Model – Views – Controllers
  3. 3. Source of data: IMDB • The Internet Movie Database (www.imdb.com) is an online database of information about movies, actors, television shows, production crew personnel, and video games. • IMDb began October 17, 1990. In 1998, it was acquired by Amazon.com. As of April 26, 2007, the site featured 981,916 titles (372,912 theatrically released) and 2,336,303 people.
  4. 4. Getting IMDb data • IMDb *always* had a data interface (Zipped text files over FTP server) • a Python implementation of the interface is available: IMDBPy • Remember: TurboGears uses Python!
  5. 5. IMDbPY • IMDbPY is a Python package useful to retrieve and manage the data of the IMDb movie database about both movies and people. • Platform-independent and written in pure Python (and few C lines), it can retrieve data from both the IMDb's web server and a local copy of the whole database.
  6. 6. Example project: Movie Collection • Idea: browse movies (with IMDB info) and store favourites with annotations • Functionality: – Search (fuzzy, showing matching titles) – Browse movie details – Store movie to favourites – Add a note
  7. 7. Uses 2 databases • Database #1: imdb.sqlite – Self generated from IMDB data – >11 hours parsing – ~ 2 GB in one file • Database #2: devdata.sqlite – Generated by Turbogears (SQLObject)
  8. 8. Model for database #2 from turbogears.database import PackageHub from sqlobject import * hub = PackageHub("imdb01") __connection__ = hub class Movie(SQLObject): title = UnicodeCol(alternateID=True, length=40) imdbid = UnicodeCol(alternateID=True, length=16) director = UnicodeCol() notes = UnicodeCol()
  9. 9. Templates • Movielist.kid • Search.kid • Browsemovie.kid • Edit.kid • Movie.kid
  10. 10. <body> <div id="status_block">Showing your collection of movies</div> <div id="sidebar"> Choose a movie or start a search <form method="post" action="../search"> <textarea name="searchterm" rows="1" cols="25"></textarea> <br/> <input type="submit" value="Search"/> </form> </div> <div class="list"> <ul> <li py:for="title in movies"><a href="movie/${title}">${title}</a></li> </ul> </div> </body> </html>
  11. 11. <body> <div id="status_block">Editing note for: <span py:content="movie.title">move title goes here</span> </div> <div id="sidebar"> You can return to the <a href="/">Movie List</a> <p/> or Search again <form method="post" action="../search"> <textarea name="searchterm" rows="1" cols="25"></textarea> <br/> <input type="submit" value="Search"/> </form> </div> <div class="note"> <form method="post" action="save"> <input type="hidden" name="title" value="${movie.title}"/> <textarea name="notes" rows="10" cols="45 ">${movie.notes}</textarea> <br/> <input type="submit" value=„Save"/> </form> </div> </body> </html>
  12. 12. Search Controller @expose(template="imdb01.templates.search") def search(self, searchterm): i = imdb.IMDb(**IMDB_PARAMS) # finding matching movies try: # Do the search, and get the results (a list of Movie objects). matchingtitles = i.search_movie(searchterm) except imdb.IMDbError, e: print "***ERROR connecting to IMDB. Complete error report:" print e if not matchingtitles: pass return dict(searchterm=searchterm, matchingtitles = matchingtitles)
  13. 13. Away with Powerpoint • Let‘s talk about the source!
  14. 14. Thanks for your attention • Questions / Comments / Get the source: – Now, or via email: LXO@CS.NOTT.AC.UK • Blog entry for this lecture: – http://www.dig-id.de/?p=35
  15. 15. Additional pointers • Of course there are similar frameworks for other programming languages, the "original" being Ruby on Rails. Original in the sense that its design was so influential that it quickly got adapted by others. Have a look at the following if you feel that you like what you saw in the lectures, but would rather do it in another language or framework: • http://en.wikipedia.org/wiki/Ruby_on_rails (Ruby) – http://www.rubyonrails.org/screencasts • http://en.wikipedia.org/wiki/Cake_php (PHP) – http://cakephp.org/screencasts • http://en.wikipedia.org/wiki/Turbogears (Python) – http://showmedo.com/videos/series?name=TurboGears20MinWiki • http://en.wikipedia.org/wiki/Django_%28web_framework%29 (Python) – http://www.throwingbeans.org/django_screencasts.html • http://en.wikipedia.org/wiki/Google_App_Engine (Python, Django) – http://www.youtube.com/watch?v=3Ztr-HhWX1c

×