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 4 and Version 5 of LargeApplication


Ignore:
Timestamp:
04/29/06 18:51:34 (13 years ago)
Author:
roger.demetrescu
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • LargeApplication

    v4 v5  
    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 a directory structure. 
    6  
    7 Most of this can be quickly alleviated with some design ideas. 
    8  
    9 Please note that these ideas are more geared towards splitting files up into what some people feel are more managable directories. 
    10  
    11 To address the needs of a truly large application, consider breaking the application into several applications and using them in conjunction with one another.  More information is in this posting on the newsgroup  
    12   * [http://groups.google.com/group/turbogears/browse_thread/thread/e95f884a6dcaee6e/4ccd6c4a5b8ad812?#4ccd6c4a5b8ad812 TG and multiple apps] 
    13  
    14  
    15 == The Controllers == 
    16  
    17 There are 2 ways to split controllers up in TurboGears 
    18  
    19 === The TG way === 
    20 Introduced in TG 0.9a2 , the tgbig template adds a controllers package to the template. 
    21  
    22 The single file controllers.py is then replaced with a controllers directory/package that consolidates the root level controllers intto controllers/root.py: 
    23  
    241{{{ 
    25         tg-admin quickstart -t tgbig  
     2#!html 
     3<br> 
     4<div style="display:block; padding: 4px; border: 2px solid red; color: #C00; font-weight:bold;"> 
     5Note: this entry was moved to TurboGears newsdoc (docs/apps/large_apps.html) 
     6</div> 
     7<br> 
    268}}} 
    27  
    28 creates 
    29  
    30   *  controllers/ 
    31     * !__init!__.py 
    32     * root.py 
    33  
    34 === The Other ways === 
    35 Some people prefer an alternate approach.  Several on the Newsgroup seemed to have implemented variations on the tgbig behaviour. 
    36          
    37 ==== The FastTrack way ==== 
    38 In FastTrack, a 'subcontrollers' directory was created 
    39 controllers.py reads as follows (abridged): 
    40  {{{ 
    41 from subcontrollers.dashboard       import DashboardController           
    42 class Root(controllers.RootController):          
    43     dashboard       = DashboardController() 
    44  }}}     
    45 subcontrollers/dashboard.py reads: 
    46  {{{ 
    47 from fasttrack.model        import Person, Project, status_codes 
    48 class DashboardController(identity.SecureResource): 
    49     require = identity.not_anonymous() 
    50 }}} 
    51   
    52 Note that model needs to be specifically addressed by namespace when being imported. 
    53  
    54 ==== Another way ==== 
    55 This was posted to the Newsgroup by justi...@ntlworld.com 
    56 {{{ 
    57 I renamed controllers.py to controller.py - the idea being that this is just the _root_ controller.  
    58 Next, I created a directory: controllers/  
    59 which contains things like:  
    60 controllers/  
    61     blog_controller.py  
    62     forum_controller.py  
    63     login_controller.py  
    64     json_api_controller.py  
    65     ...  
    66 For controller.py then:  
    67 from controllers.blog_controller import BlogController  
    68 from controllers.forum_controller import ForumController  
    69 from controllers.login_controller import LoginController  
    70 from controllers.json_api_controller import JsonApiController  
    71 class Root(controllers.RootController):  
    72     blog = BlogController()  
    73     forum = ForumController()  
    74     login = LoginController()  
    75     json_api = JsonApiController()  
    76 }}} 
    77  
    78 If this method is used, the start-APPNAME.py script must be altered to reference controller.py. 
    79   
    80 === The Difference Between the Two Approaches === 
    81  
    82 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. 
    83  
    84 === Related Newsgroup Postings: === 
    85  * [http://groups.google.com/group/turbogears/browse_thread/thread/e7fe18aadf6979da/2894f193485fde01?q=tg-big&rnum=3#2894f193485fde01 TurboGears 0.9a2 released!] 
    86  * [http://groups.google.com/group/turbogears/browse_thread/thread/776d000e0e8e3acc/56daa2795b20103c?q=tg-big&rnum=2#56daa2795b20103c bike shed #2: controllers.py vs. controllers] 
    87  
    88 == The Templates == 
    89  
    90 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.   
    91  
    92 What does work on 0.9a4 is this: 
    93  
    94  *  For any subdirectory in templates, '{{{touch __init__.py}}}' - TG/Kid/Cherrypy needs it (all versions) 
    95  *  For any template that inherits, use relative urls to the inherited document -- ie: {{{py:extends="'master.kid'"}}} should be {{{py:extends="'../master.kid'"}}}. 
    96  
    97 == The Benefits == 
    98 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. 
    99  
    100 Example: 
    101   * controller.py - commit to project lead  
    102   * controllers/ 
    103     * homepage.py - grant commit to Steve, who handles all the homepage stuff 
    104     * registration.py - grant commit to Alice 
    105   * templates/ 
    106     * homepage/ - grant commit to Steve 
    107     * registration/ - grant commit to Geoff in the art department.