fairdm.contrib.contributors.utils.helpers#

Helpers for contributor avatars, role checks and contributions.

Module Contents#

Functions#

get_contributor_avatar

Return the URL of a contributor’s avatar thumbnail.

avatar_url

Resolve a contributor’s avatar for django-mvp’s c-avatar.

current_user_has_role

Check whether the signed-in user holds any of the roles on an object.

update_or_create_contribution

Add a contributor to an object and add the given roles to their contribution.

API#

get_contributor_avatar(contributor)#

Return the URL of a contributor’s avatar thumbnail.

Args: contributor: The contributor.

Returns: The thumbnail URL, or the default user icon when there is no image.

avatar_url(contributor, size=None)#

Resolve a contributor’s avatar for django-mvp’s c-avatar.

Wired as MVP_CONFIG["brand"]["avatar_resolver"], so <c-mvp.avatar :for="contributor"> draws the contributor’s photo or logo anywhere it is used.

Args: contributor: A person, an organization, or None. size: The c-avatar size token; lg and above get the larger image.

Returns: The thumbnail URL, or None so c-avatar falls back to its placeholder.

current_user_has_role(request, obj, role)#

Check whether the signed-in user holds any of the roles on an object.

Args: request: The current request. obj: A project, dataset or sample with contributors. role: The address of a role, or a list of them.

Returns: True when the user’s contribution to the object includes any of the roles.

update_or_create_contribution(contributor, obj, roles=None)#

Add a contributor to an object and add the given roles to their contribution.

Args: contributor: The contributor to add. obj: The object to add them to. Needs a contributors manager and DEFAULT_ROLES. roles: Addresses of the roles to add. Defaults to obj.DEFAULT_ROLES.

Returns: A (contribution, created) pair, where created is False when the contributor was already on the object.