Hello,

Jorge said:
> My goal is to make the "booleanize" stuff work by default. Where teh
> predicate will return true/false if it's called from allow_only or
> @protect (sorry if that's not the name of the decorator) then
>
> result = predicate()
> if not result:
>     raise NotAuthorized

Where would that code be? In the user's controller or inside @require? Either 
way, that's already the way things work. Give it a try.


> which means the predicate is simply a function,

Just to return a Python bool, instead of another class instance?

Anyway, that function would be anything but a predicate. It won't be reusable, 
it won't be stateless. As a consequence, its result could not be used in 
@require or .allow_only -- it will be True or False forever, whatever the 
requests, because it would be evaluated when the module is loaded and will 
remain constant from there on.

The other similar thing would be to wrap the predicates around functions which 
return True/False. But it wouldn't be a good idea either:
 1.- You'd need one of those functions per predicate.
 2.- It could be dangerous. They should only be used *inside* the controller 
action (i.e., inside the method, never outside) or in the templates. This is, 
they must not be used in .allow_only or @require, for example.
 3.- You'd have to instantiate them on each function call, which would be 
inefficient:
"""
def has_permission(permission):
    predicate = repoze.what.predicates.has_permission(permission)
    return predicate.is_met(request.environ)
"""
 4.- You can already do "if my_predicate(): do_something()", thanks to the 
booleanize_predicates() monkey-patch enabled by default in TG2.


> it doesn't even needs to be tied to the SA stuff.

Nothing is tied to SQLAlchemy.

Cheers,
-- 
Gustavo Narea <xri://=Gustavo>.
| Tech blog: =Gustavo/(+blog)/tech  ~  About me: =Gustavo/about |

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