Wednesday, July 17, 2013

Reusing code between views and viewlets

You may wonder, as i did today, how you can re-use code from your View inside a Viewlet. Just to help out the occasional googler, i'm recording my solution here.

Any Viewlet has its View as an attribute (see ViewletBase's __init__ method). So in your Viewlet class, you can do something like:
Class MyViewlet(ViewletBase):
    def reused_method(self):
            return self.view.original_method()

No comments: