Hi guys,

I'm trying to hook the before_call hook in a controller for ALL
exposed methods, and have a partly working solution but wonder if this
is already solved somewhere. Any ideas? Here it is:

def patch_controller(o, f, hook_name = 'before_call'):
    for attr in dir(o):
        if not attr.startswith('__'):
            oldf = getattr(o, attr)
            if (inspect.ismethod(oldf) or inspect.isfunction(oldf))
and hasattr(oldf, 'decoration'):
                deco = Decoration.get_decoration(oldf)
                deco.register_hook(hook_name, f)
    return o

used like this:

class RootController(BaseController):
    admin = AdminController()

    def __init__(self, *args, **kw):
        BaseController.__init__(self, *args, **kw)
        patch_controller(self, self.test, 'before_render')

    def test(self, *args, **kw):
        pass


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" 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?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to