Friday, November 10, 2006

Python Decorators

I recently learned about decorators in python from this guy. And was able to implement a stack framework for django. Now I can do the following:
        def add_payment_account(request):
            rv = add_payment_account_handler(request)
            if rv is None:
                #done -> go back to caller
                rv = shortcuts.peek_stack_response(request)(request)
            return rv
Now, I realize that out of context, the above may not make much sense. Without going into the technical details of how it works. The add_payment_account page requires that a user is logged in. If a user is not logged in, they are brought to the login page, and once logged in go to add_payment_account. add_payment_account itself is pushed onto the call stack. Therefore, pages the come off of add_payement_account can pop back to add_payment_account. This framework will allow for easily creating webflows within my page.