6. Template Permissions

6.1. Overview

There are two helpers for checking a users permission against roles from within a template, this makes it easy to include functionality into the template for those users that have a certain role and hide it from those without that role.

6.2. Usage - Template Tags

The template tag implements a way of choosing what the currently logged in user will see

class portal.utils.templatetags.permissionrequired.permissionrequired
{% permissionrequired _special_all %}
<p>Show if user has the _special_all permission</p>
{% else % }
<p>Show this if they don’t have the permission</p>

{% endpermissionrequired %} The template tag permissionrequired takes one or more arguments of roles to be matched. If user has any of the listed roles the normal content is rendered.

6.3. Usage - Filter

class portal.utils.templatetags.permissionrequired.has_role

Returns a boolean if the user has the give role, or comma-separated list of roles. Can be used in conjunction with the standard if tag.

Usage:

{% if user|has_role:"Friends" %}
...
{% endif %}

or:

{% if user|has_role:"Friends,Enemies" %}
...
{% endif %}
class portal.utils.templatetags.permissionrequired.get_logged_in_roles

Returns users logged in roles.

Args:
User