Re: parameterized controllers

2008-05-31 Thread askel
Hi Wichert, What I use to avoid such repetitions is: # in BaseController # sequence of (param, attr, getter) _fetch = [] def __before__(self): for param, attr, getter in self._fetch: setattr(c, attr, getter(getattr(c, param))) # in CustomerController _getters = ( ('id',

Re: parameterized controllers

2008-05-19 Thread Aaron R
I did something similar using the __before__ method class CustomerController(BaseController): def __before__(self): if 'cust_id' in request.environ['pylons.routes_dict']: cust_id = request.environ['pylons.routes_dict'] ['cust_id']

Re: parameterized controllers

2008-05-19 Thread Wichert Akkerman
Previously Aaron R wrote: I did something similar using the __before__ method class CustomerController(BaseController): def __before__(self): if 'cust_id' in request.environ['pylons.routes_dict']: cust_id = request.environ['pylons.routes_dict'] ['cust_id']

Re: parameterized controllers

2008-05-19 Thread Dunk Fordyce
for a route like /company/:company_id/child_resource/id i do something like: class ChildResourceController(BaseController): def _get_method_args(self): args = BaseController._get_method_args(self) args['campaign'] = model.Company.get(args['campaign_id']) return args

Re: parameterized controllers

2008-05-19 Thread Mike Orr
On Mon, May 19, 2008 at 12:35 AM, Wichert Akkerman [EMAIL PROTECTED] wrote: Previously Aaron R wrote: I did something similar using the __before__ method class CustomerController(BaseController): def __before__(self): if 'cust_id' in request.environ['pylons.routes_dict']:

parameterized controllers

2008-05-18 Thread Wichert Akkerman
I seem to regularly run into a model where I would like to change how controller instantiation happens. A quite common patern I see is that you want to do something with a subitem of a model, for example manage the tasks for a particular project. With standard pylons you can easily setup a route

Re: parameterized controllers

2008-05-18 Thread Jonathan Vanasco
i'm not sure if this is the same... i often do stuff like this: class coreObjectController: def do_stuff(): Session.query( self.model_object ).blach def do_more(): pass class aCrontroller( coreObjectController ): self. model_object = class_a class bCrontroller( coreObjectController ):

Re: parameterized controllers

2008-05-18 Thread Wichert Akkerman
Previously Jonathan Vanasco wrote: i'm not sure if this is the same... i often do stuff like this: class coreObjectController: def do_stuff(): Session.query( self.model_object ).blach def do_more(): pass class aCrontroller( coreObjectController ): self. model_object =