By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,621 Members | 1,068 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,621 IT Pros & Developers. It's quick & easy.

advice about `correct' use of decorator

P: n/a
Hi all. I guess i have a conceptual question:
Im planing using a quite simple decorator to be used as a conditional
for the execution of the function. I mean something like that:

@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 :)

Cheers.
Gerardo
Aug 16 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Gerardo Herzig a écrit :
Steven Bethard wrote:
>Gerardo Herzig wrote:

>>Hi all. I guess i have a conceptual question:
Im planing using a quite simple decorator to be used as a conditional
for the execution of the function.
(snip)
>>>
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 :)

Django does it almost exactly this way:
(snip)
>
Great! So from now on, my idea is labeled as `djangothic' :)
Thanks a lot!
Which doesn't necessarily imply it's pythonic !-)

Aug 22 '07 #2

P: n/a
In message <ma***************************************@python. org>, Gerardo
Herzig wrote:
@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.
My suspicion is that most of the methods in your session object (with the
obvious exception of the login method) will require the user to be logged
in, right?

So the trouble with an extra decorator like this, is that you have to
remember to put it on nearly _all_ your methods.

Wouldn't it be simpler and safer to default the other way? Have some way of
saying "doesn't require user to be logged in", and require a valid
logged-in session on all methods where this is not specified?
Sep 1 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.