>
> where could I have found this without posting to the group ? is that 
> behaviour documented somewhere ?


Decorators are not specific to web2py -- this is standard Python. Although 
the web2py book does have a chapter covering Python basics, it is not 
intended to provide comprehensive documentation of the language. There are 
many resources online for understanding Python decorators.

Note, doing:

@check_mod_set_active
def index(): return dict(message="hello from test.py")

is essentially equivalent to something like:

def index(): return dict(message="hello from test.py")
index = check_mod_set_active(index)

When written in the latter format, it is clear that the code at the 
beginning of check_mod_set_active (i.e., checking the session and 
redirecting) gets run every time the controller is executed (even if index2 
is the function being called). Hence the need to put all the decorator code 
inside a wrapper function and return the wrapper -- that way, setting up 
the decoration doesn't do anything but generate the new modified index 
function.

Anthony

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to