Michael Brickenstein schrieb:
> Implementing __nonzero__ should eliminate the trap.

You're inspiring me to this really devilish monkey patch in TG:


from tg import request
from repoze.what.predicates import Predicate

Predicate.__nonzero__ = lambda self: self.is_met(request.environ)


With this hack, predicates can be used inside templates like this:

<p py:if="has_permission('edit-posts')">
       Congrats! You can edit blog posts.
</p>

Unfortunately, they lose the ability to work in a require decorator,
because the decorator uses repoze.what.authorize.check_authorization
which uses "predicate and predicate.check_authorization(environ)" as an
internal check. This causes our __nonzero__ method to be called. But
after changing that to "predicate is not None and ...", it works:

Check predicate instances then get a dual use inside TG, both for if
statements and for @require().

Might a bit too magical and hackish, though.


-- Christoph

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to