permission.templatetags package

Submodules

permission.templatetags.permissionif module

permissionif templatetag

class permission.templatetags.permissionif.PermissionIfParser(tokens)[source]

Bases: IfParser

Permission if parser

OPERATORS = {'!=': <class 'django.template.smartif.infix.<locals>.Operator'>, '<': <class 'django.template.smartif.infix.<locals>.Operator'>, '<=': <class 'django.template.smartif.infix.<locals>.Operator'>, '==': <class 'django.template.smartif.infix.<locals>.Operator'>, '>': <class 'django.template.smartif.infix.<locals>.Operator'>, '>=': <class 'django.template.smartif.infix.<locals>.Operator'>, 'and': <class 'django.template.smartif.infix.<locals>.Operator'>, 'has': <class 'django.template.smartif.infix.<locals>.Operator'>, 'in': <class 'django.template.smartif.infix.<locals>.Operator'>, 'is': <class 'django.template.smartif.infix.<locals>.Operator'>, 'is not': <class 'django.template.smartif.infix.<locals>.Operator'>, 'not': <class 'django.template.smartif.prefix.<locals>.Operator'>, 'not in': <class 'django.template.smartif.infix.<locals>.Operator'>, 'of': <class 'django.template.smartif.infix.<locals>.Operator'>, 'or': <class 'django.template.smartif.infix.<locals>.Operator'>}

use extra operator

translate_token(token)[source]
class permission.templatetags.permissionif.TemplatePermissionIfParser(parser, *args, **kwargs)[source]

Bases: PermissionIfParser

create_var(value)[source]
error_class

alias of TemplateSyntaxError

permission.templatetags.permissionif.do_permissionif(parser, token)[source]

Permission if templatetag

Examples

{% if user has 'blogs.add_article' %}
    <p>This user have 'blogs.add_article' permission</p>
{% elif user has 'blog.change_article' of object %}
    <p>This user have 'blogs.change_article' permission of {{object}}</p>
{% endif %}

{# If you set 'PERMISSION_REPLACE_BUILTIN_IF = False' in settings #}
{% permission user has 'blogs.add_article' %}
    <p>This user have 'blogs.add_article' permission</p>
{% elpermission user has 'blog.change_article' of object %}
    <p>This user have 'blogs.change_article' permission of {{object}}</p>
{% endpermission %}
permission.templatetags.permissionif.has_operator(context, x, y)[source]

‘has’ operator of permission if

This operator is used to specify the user object of permission

permission.templatetags.permissionif.of_operator(context, x, y)[source]

‘of’ operator of permission if

This operator is used to specify the target object of permission

permission.templatetags.permissionif.replace_builtin_if(replace=False)[source]

Module contents