Modelling a Turbogears Application

As I was envisioning the structure of the code for this blog, I was reminded of the style of module or functional modelling, as opposed to a strictly object-oriented approach

Posted by 11/09/2005

I have been working with Turbogears lately. One thing I noticed is that it gives an application a clean interface that is easy to model.

turbogears model

Modelling a Turbogears application

Putting together this blog in Turbogears I was thinking of how I visualized the structure. What I envisioned reminded me of old style module based documentation i.e. function based. The method of matching a url to a method is very much a functional view of the interactions and workings of a web site. There is a simplicity and directness of this approach that is nice to work with after setting up the struts-config.xml, ActionForwards, FormBeans and the like in the Struts framework. All I have to do to activate the controllers for the site is something like this:


cherrypy.root = Root()
cherrypy.root.blog = BlogController()
cherrypy.root.blog.admin = AdminController()
cherrypy.root.blog.archives = ArchivesController()
cherrypy.root.blog.categories = CategoriesController()
cherrypy.root.blog.comments = CommentsController()

And then each of the controllers just has a method to match a url and the parameters are the parameters that are sent to the function. So there is no method with a necessary (HttpRequest request) parameter - and no need for request.getParameter("parameter");. So, for instance, the pages that group posts by category are as simple as this:


class CategoriesController:
@turbogears.expose(html="klangorg.templates.blog.category")
def default(self,category):
return self.category(category)

@turbogears.expose(html="klangorg.templates.blog.category")
def category(self,categoryID):
category = Category.get(categoryID)
return dict(category=category)

because the SQLObject mapper gives me categories.posts() for free.

The structure I visualized looked something like the picture.

Comments

billie commented, on September 19, 2008 at 6:42 p.m.:
miriam commented, on October 1, 2008 at 4:24 p.m.:
carole commented, on October 1, 2008 at 8:16 p.m.:
mae commented, on October 2, 2008 at 4:41 p.m.:
cherly commented, on October 3, 2008 at 11:53 a.m.:
meta commented, on October 3, 2008 at 3:24 p.m.:
misty commented, on October 3, 2008 at 5:20 p.m.:
marvel commented, on October 3, 2008 at 7:04 p.m.:
floyd commented, on October 4, 2008 at 8:16 p.m.:
orpha commented, on October 4, 2008 at 10:14 p.m.:
priscilla commented, on October 23, 2008 at 5:51 a.m.:

http://esgit.com/8/map413.html http://homebuyall.com/11/map2.html http://esgit.com/8/map152.html http://homebuyall.com/15/map354.html http://homebuyall.com/13/map428.html http://homebuyall.com/14/map216.html http://homebuyall.com/11/map228.html http://esgit.com/5/map115.html http://esgit.com/7/map482.html http://homebuyall.com/14/map278.html http://esgit.com/6/map491.html http://homebuyall.com/14/map470.html http://homebuyall.com/15/map138.html http://esgit.com/7/map431.html http://homebuyall.com/14/map395.html http://esgit.com/6/map286.html http://esgit.com/5/map490.html http://homebuyall.com/15/map452.html http://esgit.com/9/map348.html http://esgit.com/7/map13.html http://esgit.com/7/map151.html http://homebuyall.com/11/map226.html http://esgit.com/5/map30.html http://esgit.com/8/map107.html http://homebuyall.com/11/map130.html http://homebuyall.com/14/map285.html http://esgit.com/5/map347.html http://esgit.com/7/map334.html http://esgit.com/8/map358.html http://esgit.com/8/map367.html http://homebuyall.com/11/map457.html http://homebuyall.com/13/map211.html http://homebuyall.com/14/map264.html http://homebuyall.com/15/map28.html http://homebuyall.com/13/map54.html http://homebuyall.com/12/map198.html http://homebuyall.com/13/map241.html http://esgit.com/7/map211.html http://homebuyall.com/12/map302.html http://esgit.com/5/map156.html http://esgit.com/5/map465.html http://homebuyall.com/14/map237.html http://homebuyall.com/15/map116.html http://esgit.com/5/map68.html http://esgit.com/6/map151.html http://homebuyall.com/13/map494.html http://esgit.com/6/map352.html http://esgit.com/7/map121.html http://homebuyall.com/13/map442.html http://homebuyall.com/12/map164.html

lloyd commented, on November 23, 2008 at 4:21 p.m.:
bobbie commented, on November 23, 2008 at 5:05 p.m.:
felicia commented, on November 23, 2008 at 7:20 p.m.:
dianne commented, on November 23, 2008 at 11:39 p.m.:
lloyd commented, on November 24, 2008 at 12:43 a.m.:
jon commented, on November 24, 2008 at 3:13 a.m.:
toni commented, on November 24, 2008 at 3:18 a.m.:
kori commented, on November 24, 2008 at 4:41 a.m.:
toni commented, on November 24, 2008 at 6:57 a.m.:
mirian commented, on November 24, 2008 at 7:08 a.m.:
floyd commented, on November 24, 2008 at 12:39 p.m.:
dianne commented, on November 24, 2008 at 2:35 p.m.:
jenny commented, on November 24, 2008 at 4 p.m.:
pennie commented, on December 17, 2008 at 9:19 a.m.:

Post a comment


Total: 0.10 Python: 0.08 DB: 0.02 Queries: 33