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

Changes between Initial Version and Version 1 of LargeApplication

04/23/06 11:25:15 (13 years ago)

CnP'd from "LageApplication"


  • LargeApplication

    v1 v1  
     1TG 0.9a4 
     3= Designing for a 'Large' Application = 
     5The default TG setup is a little more Pythonic than some web developers are used to, and doesn't lend itself well to a collaborative development environment that uses Subversion to enforce different permissions based on directory structure. 
     7Most of this can be quickly alleviated with some design ideas. 
     9== The Controllers == 
     11There are 2 ways to split controllers up in TurboGears 
     13=== The TG way === 
     14Introduced in TG 0.9a2 , the tgbig template adds a controllers package to the template. 
     16The single file controllers.py is then replaced with a controllers directory/package that consolidates the root level controllers intto controllers/root.py: 
     19        tg-admin quickstart -t tgbig  
     24  *  controllers/ 
     25    * !__init!__.py 
     26    * root.py 
     28=== The Other ways === 
     29Some people prefer an alternate approach.  Several on the Newsgroup seemed to have implemented variations on the tgbig behaviour. 
     31==== The FastTrack way ==== 
     32In FastTrack, a 'subcontrollers' directory was created 
     33controllers.py reads as follows (abridged): 
     34 {{{ 
     35from subcontrollers.dashboard       import DashboardController           
     36class Root(controllers.RootController):          
     37    dashboard       = DashboardController() 
     38 }}}     
     39subcontrollers/dashboard.py reads: 
     40 {{{ 
     41from fasttrack.model        import Person, Project, status_codes 
     42class DashboardController(identity.SecureResource): 
     43    require = identity.not_anonymous() 
     46Note that model needs to be specifically addressed by namespace when being imported. 
     48==== Another way ==== 
     49This was posted to the Newsgroup by justi...@ntlworld.com 
     51I renamed controllers.py to controller.py - the idea being that this is just the _root_ controller.  
     52Next, I created a directory: controllers/  
     53which contains things like:  
     55    blog_controller.py  
     56    forum_controller.py  
     57    login_controller.py  
     58    json_api_controller.py  
     59    ...  
     60For controller.py then:  
     61from controllers.blog_controller import BlogController  
     62from controllers.forum_controller import ForumController  
     63from controllers.login_controller import LoginController  
     64from controllers.json_api_controller import JsonApiController  
     65class Root(controllers.RootController):  
     66    blog = BlogController()  
     67    forum = ForumController()  
     68    login = LoginController()  
     69    json_api = JsonApiController()  
     72If this method is used, the start-APPNAME.py script must be altered to reference controller.py. 
     74=== The Difference Between the Two Approaches === 
     76The 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: they 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. 
     78=== Related Newsgroup Postings: === 
     79 * [http://groups.google.com/group/turbogears/browse_thread/thread/e7fe18aadf6979da/2894f193485fde01?q=tg-big&rnum=3#2894f193485fde01 TurboGears 0.9a2 released!] 
     80 * [http://groups.google.com/group/turbogears/browse_thread/thread/776d000e0e8e3acc/56daa2795b20103c?q=tg-big&rnum=2#56daa2795b20103c bike shed #2: controllers.py vs. controllers] 
     82== The Templates == 
     84The 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 0.9a4.   
     86What does work on 0.9a4 is this: 
     88 *  For any subdirectory in templates, '{{{touch __init__.py}}}' - TG/Kid/Cherrypy needs it (all versions) 
     89 *  For any template that inherits, use relative urls to the inherited document -- ie: {{{py:extends="'master.kid'"}}} should be {{{py:extends="'../master.kid'"}}}. 
     91== The Benefits == 
     92Aside from cleaning up the files and letting a team work on components separately, you get the benefit of using SVN to indpendently manage permissions. 
     95  * controller.py - commit to project lead  
     96  * controllers/ 
     97    * homepage.py - grant commit to Steve, who handles all the homepage stuff 
     98    * registration.py - grant commit to Alice 
     99  * templates/ 
     100    * homepage/ - grant commit to Steve 
     101    * registration/ - grant commit to Geoff in the art department.