Source code for superdjango.contrib.accounts.impersonation.context_processors

"""
Library of context processors.

"""

# Imports

from .utils import user_is_allowed_to_impersonate as _user_is_allowed_to_impersonate

# Exports

__all__ = (
    "user_is_allowed_to_impersonate",
)

# Processors


# noinspection PyUnusedLocal
[docs]def user_is_allowed_to_impersonate(request): """Add a flag which indicates whether the current user is allowed to impersonate another user. :param request: The request instance is not used. :type: request: object :rtype: dict """ # The current user may already be an impersonator. user = getattr(request, "impersonator", None) if user is None: user = request.user return { 'user_is_allowed_to_impersonate': _user_is_allowed_to_impersonate(user) }