On Thu, Jan 20, 2011 at 8:40 AM, Landreville <[email protected]> wrote:
> On Jan 20, 11:16 am, Antonio Beamud <[email protected]> wrote:
>> What's the better way to check permissions, groups or auth inside a mako
>> template, for example, to show only part of the web page based on the
>> user accessing it.
>> Now, I'm using something like this:
>>
>>   class MyController(BaseController):
>>      def index(self):
>>         c.is_manager = in_group('manager').is_met(request.environ)
>>         return render('/index.mako')
>>
>> In the index.mako template:
>>
>> ...
>> %if c.is_manager:
>> <p>Hello manager</p>
>
> I'm doing just what you did in my templates, although I use
> "c.is_manager = is_met(has_permission('edit-something'))" . You could
> also make is_met and repoze.what.predicates default imports in the
> mako templates (in config/environment.py) and use them directly in the
> template, but that seems like too much logic in the template for my
> liking.

I do ``c.can_do_this``.  The calculation may get more complex over
time as the client asks for more nuances, or you may switch to a
different authorization library. In either case it's easier to
maintain in the controller.

A possible exception may be in a loop, where it's too cumbersome to
precalculate an array of permissions for all rows. But this is rare:
usually an entire row is either permitted or unpermitted, and the db
query can exclude unpermitted records.
-- 
Mike Orr <[email protected]>

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" 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/pylons-discuss?hl=en.

Reply via email to