advice about `correct' use of decorator

Gregor Horvath gh at gregor-horvath.com
Mon Sep 3 07:40:49 EDT 2007


Gerardo Herzig schrieb:
> 
> @is_logued_in
> def change_pass():
>    bla
>    bla
> 
> And so on for all the other functions who needs that the user is still 
> loged in.
> 
> where obviosly the is_logued_in() function will determine if the dude is 
> still loged in, and THEN execute change_pass(). If the dude is not loged 
> in, change_pass() is NOT executed at all. Instead, it will be redirected 
> to the `login' screen.
> 
> Something in my mind tells me that this is not the pythonic way...But i 
> like the idea, so please tell me that im in the right way :)
> 

That's how turbogears does it.
See:

http://docs.turbogears.org/1.0/UsingIdentity?highlight=%28identity%29


Greg



More information about the Python-list mailing list