Hi,

For some time I have been thinking on which will be the best way to
"merge" two controllers into the same PATH, percious made a suggestion
the other day on IRC which IMO is brilliant.

it was something along the way of

"They are classes simply make a subclass of both controllers"

Ever since we have been using it for tgext.pages, which got me
thinking. Why don't we do that with quickstart? well here is the
result.

The code simply splits the "RootController" into 3 controllers.
AuthenticationController (login,logout, post_login, post_logout),
DemoController (about,index,auth,manage_permission_only,editor_use_only)
and RootController (admin, error, extends both of the above)

IMO this is
- way nicer (cleaner) than the original "everything smashed together" approach
- It introduces new and old users, to this great idea of mounting 2
controllers to pull functionality together
- it's not magical at all (because you do know that python has
multiple inheritance do you?)
-it's also great to help non-newbies in getting rid of the "newbie"
oriented part of the quickstart.
- it simplifies the quickstart code a lot (removes a bunch of if/elif blocks).

In fact I think the AuthenticationController could be moved inside
/lib together with BaseController as it's something people aren't
going to change a lot.

is this going back to the SecureController/Controller stuff? well kind
of but not really as we aren't making two separate hierarchies we are
making just one.

PS: the code hasn't been adapted for no-auth controllers I wanted to
see if it was commitable before getting it into full shape.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears Trunk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/turbogears-trunk?hl=en
-~----------~----~----~----~------~----~------~--~---

Index: devtools/templates/turbogears/+package+/controllers/root.py_tmpl
===================================================================
--- devtools/templates/turbogears/+package+/controllers/root.py_tmpl	(revision 6505)
+++ devtools/templates/turbogears/+package+/controllers/root.py_tmpl	(working copy)
@@ -18,29 +18,10 @@
 
 __all__ = ['RootController']
 
+{{if auth == "sqlalchemy"}}
 
-class RootController(BaseController):
-    """
-    The root controller for the {{project}} application.
-    
-    All the other controllers and WSGI applications should be mounted on this
-    controller. For example::
-    
-        panel = ControlPanelController()
-        another_app = AnotherWSGIApplication()
-    
-    Keep in mind that WSGI applications shouldn't be mounted directly: They
-    must be wrapped around with :class:`tg.controllers.WSGIAppController`.
-    
-    """
-{{if auth == "sqlalchemy"}}
+class DemoController(BaseController):
     secc = SecureController()
-    
-    admin = Catwalk(model, DBSession)
-{{endif}}
-    
-    error = ErrorController()
-
     @expose('{{package}}.templates.index')
     def index(self):
         """Handle the front-page."""
@@ -51,14 +32,11 @@
         """Handle the 'about' page."""
         return dict(page='about')
 
-    {{if auth == "sqlalchemy"}}
     @expose('{{package}}.templates.authentication')
     def auth(self):
         """Display some information about auth* on this application."""
         return dict(page='auth')
-    {{endif}}
 
-{{if auth == "sqlalchemy"}}
     @expose('{{package}}.templates.index')
     @require(predicates.has_permission('manage', msg=l_('Only for managers')))
     def manage_permission_only(self, **kw):
@@ -71,6 +49,7 @@
         """Illustrate how a page exclusive for the editor works."""
         return dict(page='editor stuff')
 
+class AuthenticationController(BaseController):
     @expose('{{package}}.templates.login')
     def login(self, came_from=url('/')):
         """Start the user login."""
@@ -104,3 +83,24 @@
         flash(_('We hope to see you soon!'))
         redirect(came_from)
 {{endif}}
+
+class RootController(DemoController,AuthenticationController):
+    """
+    The root controller for the {{project}} application.
+    
+    All the other controllers and WSGI applications should be mounted on this
+    controller. For example::
+    
+        panel = ControlPanelController()
+        another_app = AnotherWSGIApplication()
+    
+    Keep in mind that WSGI applications shouldn't be mounted directly: They
+    must be wrapped around with :class:`tg.controllers.WSGIAppController`.
+    
+    """
+{{if auth == "sqlalchemy"}}
+    admin = Catwalk(model, DBSession)
+{{endif}}
+    error = ErrorController()
+
+
Index: devtools/templates/turbogears/+package+/lib/base.py_tmpl
===================================================================
--- devtools/templates/turbogears/+package+/lib/base.py_tmpl	(revision 6505)
+++ devtools/templates/turbogears/+package+/lib/base.py_tmpl	(working copy)
@@ -17,17 +17,6 @@
 __all__ = ['Controller', 'BaseController']
 
 
-class Controller(object):
-    """
-    Base class for a web application's controller.
-
-    Currently, this provides positional parameters functionality
-    via a standard default method.
-
-    """
-    pass
-
-
 class BaseController(TGController):
     """
     Base class for the controllers in the application.

Reply via email to