On Tue, 01 Aug 2006 17:57:01 -0700 "Michele Cella" <[EMAIL PROTECTED]> wrote:
> > > Jason Chu wrote: > > On Wed, 2 Aug 2006 02:09:20 +0200 > > Alberto Valverde <[EMAIL PROTECTED]> wrote: > > > > > We can still keep the good 'ol variable_providers untouched for > > > backwards compatibility. > > > > I like variable_providers, it lets me specify things that are > > available throughout the entire application, instead of on a > > controller-by-controller basis (I assume you're not going to walk > > the controller tree up just to see what variables to apply). > > > > If we got rid of variable_providers entirely I'd be annoyed that > > turbogears can stuff things into the global kid namespace but I > > can't (the tg variable). > > You could do that in a more elegant way: > > 1) By adding your method to the base Controller class before creating > an instance of it: > > from turbogears import Controller > > def my_global_provider(self): > return dict(#stuff that into every template) > > Controller.__variables__ = my_global_provider > > class BlogController(Controller): > .... As long as the BlogController did something like (assuming you wanted to use BlogController too): parent = super(BlogController, self).__variables__ return parent.update(dict(stuff that into every controller)) And that's assuming that all controllers are using the Controller class (we still don't have that restriction, do we?) Does RootController derive from Controller? > 2) By subclassing the Controller class and using that new class as > your controller > > class ApplicationController(Controller): > def __variables__(self): > return dict(stuff that into every controller) > > This solution allows you to keep tg uncluttered by your stuffs and at > the same time you can stuff anything into *every* templates or just > *some* templates in the way you want, this means you can use custom > namespace or object to group things (and not just tg) or just plain > methods or widget instances. ;-) Keeping tg's namespace uncluttered is kind of nice, but having custom controllers to pass around variable_providers everywhere is kind of annoying. Doesn't that mean any given combination of parent-namespace-providing controllers will have to be handled specially? Instead of just stuffing everything into variable_providers? > Ciao > Michele Jason
signature.asc
Description: PGP signature

