Define Dashboard related utilities and miscellaneous logic.

Copyright (C) 2021 Gitcoin Core

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see http://www.gnu.org/licenses/.



Humanize an event name.

Args: name (str): The event name

Returns: str: The humanized representation.


create_user_action(user, action_type, request=None, metadata=None)

Create a UserAction for the specified action type.

Args: user (User): The User object. action_type (str): The type of action to record. request (Request): The request object. Defaults to: None. metadata (dict): Any accompanying metadata to be added. Defaults to: {}.

Returns: bool: Whether or not the UserAction was created successfully.


get_ipfs(host=None, port=5001)

Establish a connection to IPFS.

Args: host (str): The IPFS host to connect to. Defaults to environment variable: IPFS_HOST. The host name should be of the form 'ipfs.infura.io' and not include 'https://'. port (int): The IPFS port to connect to. Defaults to environment variable: env IPFS_API_PORT.

Raises: CommunicationError: The exception is raised when there is a communication error with IPFS.

Returns: ipfshttpclient.client.Client: The IPFS connection client.


get_web3(network, sockets=False, chain='std')

Get a Web3 session for the provided network.

Attributes: network (str): The network to establish a session with.

Raises: UnsupportedNetworkException: The exception is raised if the method is passed an invalid network.

Returns: web3.main.Web3: A web3 instance for the provided network.



Get a graphQL client attached to the given uri

Returns: GraphQLClient: an established GraphQLClient associated with the given uri


get_graphql_result(uri, query)

Get result of the query from the uri

Returns: dict: result of the graphQL query


get_bounty_invite_url(inviter, bounty_id)

Returns a unique url for each bounty and one who is inviting Returns: A unique string for each bounty



Returns a unique url for each bounty and one who is inviting

Returns: A unique string for each bounty



Process web3 bounty data by creating new or updated Bounty objects.



Build the profile pairs list of tuples for ingestion by notifications.

Args: bounty (dashboard.models.Bounty): The Bounty to build profile pairs for.

Returns: list of tuples: The list of profile pair tuples.



Handle cardinal to ordinal representation of numeric values.

Args: num (int): The integer to be converted from cardinal to ordinal numerals.

Returns: str: The ordinal representation of the provided integer.


record_user_action_on_interest(interest, event_name, last_heard_from_user_days)

Record User actions and activity for the associated Interest.


get_context(ref_object=None, github_username='', user=None, confirm_time_minutes_target=4, confirm_time_slow=120, confirm_time_avg=15, confirm_time_fast=1, active='', title='', update=None)

Get the context dictionary for use in view.



Clean the Bounty URL of unsavory characters.

The primary utility of this method is to drop issuecomment blocks from Github issue URLs copy/pasted via comments.

Args: url (str): The Bounty VC URL.

TODO: * Deprecate this in favor of Django forms.

Returns: str: The cleaned Bounty URL.


profile_helper(handle, suppress_profile_hidden_exception=False, current_user=None, disable_cache=False, full_profile=False)

Define the profile helper.

Args: handle (str): The profile handle.

Raises: DoesNotExist: The exception is raised if a Profile isn't found matching the handle. Remediation is attempted by syncing the profile data. MultipleObjectsReturned: The exception is raised if multiple Profiles are found. The latest Profile will be returned.

Returns: dashboard.models.Profile: The Profile associated with the provided handle.