fairdm.contrib.contributors.utils.helpers#
Helpers for contributor avatars, role checks and contributions.
Module Contents#
Functions#
Return the URL of a contributor’s avatar thumbnail. |
|
Resolve a contributor’s avatar for django-mvp’s |
|
Check whether the signed-in user holds any of the roles on an object. |
|
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-avatarsize token; lg and above get the larger image.Returns: The thumbnail URL, or None so
c-avatarfalls 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
contributorsmanager andDEFAULT_ROLES. roles: Addresses of the roles to add. Defaults toobj.DEFAULT_ROLES.Returns: A
(contribution, created)pair, wherecreatedis False when the contributor was already on the object.