wiki:LageApplication
Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Version 3 (modified by anonymous, 13 years ago) (diff)

--

TG 0.9a4

Designing for a 'Large' Application

The default TG setup is a little more Pythonic than some web developers are used to, and doesn't lend well to a collaborative development environment that uses SVN for different permissions based on directory structure.

Most of this can be quickly alleviated with some design ideas.

The Controllers

There are 2 ways to split controllers up in TurboGears

The TG way

Introduced in TG 0.9a2 , the tgbig template adds a controllers package to the template.

the single file controllers.py is then replaced with a controllers directory/package that consolidates the root level controllers to controllers/root.py

	tg-admin quickstart -t tgbig 

creates

  • controllers/
    • init.py
    • root.py

The Other ways

Some people prefer an alternal approach. Several on the Newsgroup seemed to have implemented variations on the tgbig behaviour

The FastTrack? way

In FastTrack?, a 'subcontrollers' directory was created controllers.py reads as follows (abridged):

from subcontrollers.dashboard       import DashboardController     	
class Root(controllers.RootController): 	
    dashboard       = DashboardController()

subcontrollers/dashboard.py reads:

from fasttrack.model        import Person, Project, status_codes
class DashboardController(identity.SecureResource):
    require = identity.not_anonymous()

Note that model needs to be specifically addressed in regards to namespace when being imported

Another way

This was posted to the Newsgroup by justi...@…

I renamed controllers.py to controller.py - the idea being that this is just the _root_ controller. 
Next, I created a directory: controllers/ 
which contains things like: 
controllers/ 
    blog_controller.py 
    forum_controller.py 
    login_controller.py 
    json_api_controller.py 
    ... 
For controller.py then: 
from controllers.blog_controller import BlogController 
from controllers.forum_controller import ForumController 
from controllers.login_controller import LoginController 
from controllers.json_api_controller import JsonApiController 
class Root(controllers.RootController): 
    blog = BlogController() 
    forum = ForumController() 
    login = LoginController() 
    json_api = JsonApiController() 

if this method is used, the start-APPNAME.py script must be altered to reference controller.py

The Difference Between the Two Approaches

The main difference between the approaches is that tgbig is more 'pythonic' -- controllers is a package, with root.py being the main controller. the alternate methods are more simlar to other web frameworks, and keep controller(s).py as the main controller and mount a tree of controllers under it - much like a tree of directories on a web server.

Related Newsgroup Postings:

The Templates

The way to get templates into subdirectories seems to change based on TG revisions - I tried some tricks from the newsgroup ( Some people said import each template directly, others created controllers to juggle namspace issues ) but none worked on .09a4.

What does work on 0.9a4 , is this:

  • For any subdirectory in templates, 'touch init.py' - TG/Kid/Cherrypy needs it (all versions)
  • For any template that inherits , use relative urls to the inherited document -- ie: py:extends="'master.kid'" should be py:extends="'../master.kid'"

The Benefits

Aside from cleaning up the files and letting a team work on components seperately, you get the benefit of using SVN to indpendantly manage permissions

Example:

  • controller.py - commit to project lead
  • controllers/
    • homepage.py - grant commit to Steve, who handles all the homepage stuff
    • registration.py - grant commit to Alice
  • templates/
    • homepage/ - grant commit to Steve
    • registration/ - grant commit to Geoff in the art department.