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',
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']
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']
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
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']:
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
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 ):
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 =