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 Version 1 and Version 2 of LargeApplication


Ignore:
Timestamp:
04/23/06 11:26:27 (13 years ago)
Author:
rob@…
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • LargeApplication

    v1 v2  
    1 TG 0.9a4 
    2  
    3 = Designing for a 'Large' Application = 
    4  
    5 The 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. 
    6  
    7 Most of this can be quickly alleviated with some design ideas. 
    8  
    9 == The Controllers == 
    10  
    11 There are 2 ways to split controllers up in TurboGears 
    12  
    13 === The TG way === 
    14 Introduced in TG 0.9a2 , the tgbig template adds a controllers package to the template. 
    15  
    16 The single file controllers.py is then replaced with a controllers directory/package that consolidates the root level controllers intto controllers/root.py: 
    17  
    18 {{{ 
    19         tg-admin quickstart -t tgbig  
    20 }}} 
    21  
    22 creates 
    23  
    24   *  controllers/ 
    25     * !__init!__.py 
    26     * root.py 
    27  
    28 === The Other ways === 
    29 Some people prefer an alternate approach.  Several on the Newsgroup seemed to have implemented variations on the tgbig behaviour. 
    30          
    31 ==== The FastTrack way ==== 
    32 In FastTrack, a 'subcontrollers' directory was created 
    33 controllers.py reads as follows (abridged): 
    34  {{{ 
    35 from subcontrollers.dashboard       import DashboardController           
    36 class Root(controllers.RootController):          
    37     dashboard       = DashboardController() 
    38  }}}     
    39 subcontrollers/dashboard.py reads: 
    40  {{{ 
    41 from fasttrack.model        import Person, Project, status_codes 
    42 class DashboardController(identity.SecureResource): 
    43     require = identity.not_anonymous() 
    44 }}} 
    45   
    46 Note that model needs to be specifically addressed by namespace when being imported. 
    47  
    48 ==== Another way ==== 
    49 This was posted to the Newsgroup by justi...@ntlworld.com 
    50 {{{ 
    51 I renamed controllers.py to controller.py - the idea being that this is just the _root_ controller.  
    52 Next, I created a directory: controllers/  
    53 which contains things like:  
    54 controllers/  
    55     blog_controller.py  
    56     forum_controller.py  
    57     login_controller.py  
    58     json_api_controller.py  
    59     ...  
    60 For controller.py then:  
    61 from controllers.blog_controller import BlogController  
    62 from controllers.forum_controller import ForumController  
    63 from controllers.login_controller import LoginController  
    64 from controllers.json_api_controller import JsonApiController  
    65 class Root(controllers.RootController):  
    66     blog = BlogController()  
    67     forum = ForumController()  
    68     login = LoginController()  
    69     json_api = JsonApiController()  
    70 }}} 
    71  
    72 If this method is used, the start-APPNAME.py script must be altered to reference controller.py. 
    73   
    74 === The Difference Between the Two Approaches === 
    75  
    76 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: 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. 
    77  
    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] 
    81  
    82 == The Templates == 
    83  
    84 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 0.9a4.   
    85  
    86 What does work on 0.9a4 is this: 
    87  
    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'"}}}. 
    90  
    91 == The Benefits == 
    92 Aside from cleaning up the files and letting a team work on components separately, you get the benefit of using SVN to indpendently manage permissions. 
    93  
    94 Example: 
    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.   
     1This page is a typo. Moved to LargeApplication.