dashboard.utils

Define Dashboard related utilities and miscellaneous logic.

Copyright (C) 2018 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_event_name

humanize_event_name(name)

Humanize an event name.

Args: name (str): The event name

Returns: str: The humanized representation.

create_user_action

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

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. 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: ipfsapi.client.Client: The IPFS connection client.

get_web3

get_web3(network, sockets=False)

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.

web3_process_bounty

web3_process_bounty(bounty_data)

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

build_profile_pairs

build_profile_pairs(bounty)

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.

get_ordinal_repr

get_ordinal_repr(num)

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

record_user_action_on_interest(interest, event_name, last_heard_from_user_days)

Record User actions and activity for the associated Interest.

get_context

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_bounty_url

clean_bounty_url(url)

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.