Skip to content

Users tags

hypha.apply.users.templatetags.users_tags

register module-attribute

register = Library()

backend_name

backend_name(name)

Human readable mapping for the social auth backend

Source code in hypha/apply/users/templatetags/users_tags.py
@register.filter
def backend_name(name):
    """Human readable mapping for the social auth backend"""
    return {
        "google-oauth": "Google OAuth",
        "google-oauth2": "Google OAuth",
        "google-openidconnect": "Google OpenId",
    }.get(name, name)

backend_class

backend_class(backend)
Source code in hypha/apply/users/templatetags/users_tags.py
@register.filter
def backend_class(backend):
    return backend.replace("-", " ")

can_use_oauth

can_use_oauth(context)
Source code in hypha/apply/users/templatetags/users_tags.py
@register.simple_tag(takes_context=True)
def can_use_oauth(context):
    user = context.get("user")

    return can_use_oauth_check(user)

user_2fa_enabled

user_2fa_enabled(user)

Checking if 2FA devices exist for the user

Source code in hypha/apply/users/templatetags/users_tags.py
@register.simple_tag
def user_2fa_enabled(user):
    """Checking if 2FA devices exist for the user"""
    if len(list(devices_for_user(user))):
        return True
    return False

tokens_text

tokens_text(token_set)
Source code in hypha/apply/users/templatetags/users_tags.py
@register.simple_tag
def tokens_text(token_set):
    tokens_string = ""
    for token in token_set:
        tokens_string += str(token.token) + " \n"
    return tokens_string

user_image

user_image(identifier, size=20)
Source code in hypha/apply/users/templatetags/users_tags.py
@register.simple_tag
def user_image(identifier: str, size=20):
    return SafeString(get_identicon(identifier, size=size))

get_user_submission_count

get_user_submission_count(user)

Get the number of submissions associated to either one user or a list of users

Also handles Wagtail's user deletion view where a list of dicts containing {"item": } gets passed

Parameters:

  • user (User | Iterable[User | Dict[Literal['item'], User]]) –

    A user object OR an iterable containing either User objects/dictionaries of {"item": }

Returns:

  • int –

    Count of all submissions associated to the user(s)

Raises:

  • TypeError –

    when none of the previously specified types are provided in user

Source code in hypha/apply/users/templatetags/users_tags.py
@register.filter
def get_user_submission_count(
    user: User | Iterable[User | Dict[Literal["item"], User]],
) -> int:
    """Get the number of submissions associated to either one user or a list of users

    Also handles Wagtail's user deletion view where a list of dicts containing {"item": <User Object>} gets passed

    Args:
        user: A user object OR an iterable containing either User objects/dictionaries of {"item": <User Object>}

    Returns:
        Count of all submissions associated to the user(s)

    Raises:
        TypeError: when none of the previously specified types are provided in `user`
    """
    ApplicationSubmission = apps.get_model("funds", "ApplicationSubmission")
    if isinstance(user, User):
        users = [user]
    elif isinstance(user, abc.Iterable):
        users = [x["item"] if isinstance(x, dict) else x for x in user]
    else:
        raise TypeError(
            "User instance or iterable of users not provided to get_user_submission_count!"
        )
    return ApplicationSubmission.objects.filter(user__in=users).count()