Gustavo Narea schrieb:
> Hello, everybody.
>
> I've tried to implement the @require decorator into TG with this code:
> http://paste.turbogears.org/paste/13386
>
> However, that HTTPUnauthorized exception is not handled neither by TurboGears
> nor repoze.who and I'm sure it's because I'm missing something -- but what?
Erm, I'm not sure, but from the looks of it your decorator doesn't do
anything.
It will retrieve a predicate, then it's called with a function to
decorate. This is a *module init*-time! But you then check for
authorization, and then simply return the function unmodified...
The decorator should look like this:
from decorator import decorator
def require(predicate):
@decorator
def check_authorization(func, *args, **kwargs):
environ = request.environ
try:
check_authorization(predicate, environ)
except NotAuthorizedError, e:
flash(e.errors, status="status_error")
raise HTTPUnauthorized()
return func(*args, **kwargs)
return check_authorization
> Anyway, this is how that decorator was defined in tgext.authorization:
> http://trac.turbogears.org/browser/projects/tgAuthorization/trunk/tgext/authorization/authorize.py?rev=5629#L350
>
> What am I doing wrong? I've seen something called "hooks" in tg.decorators,
> but it's not very clear to me how they work and if I should use them for this.
>
> Thanks in advance.
Dunno much about hooks.
Diez
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears Trunk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/turbogears-trunk?hl=en
-~----------~----~----~----~------~----~------~--~---