dashboard.helpers

Handle dashboard helpers and related 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/.

get_bounty_view_kwargs

get_bounty_view_kwargs(request)

Get the relevant kwargs from the request.

handle_bounty_views

handle_bounty_views(request)

Handle bounty view entry.

Attributes: bounty (dashboard.Bounty): The bounty object for the specified request. bounty_kwargs (dict): The relevant key/values from the request to be used for the Bounty query.

Returns: dashboard.Bounty: The Bounty object.

amount

amount(request)

Determine the value of the provided denomination and amount in ETH and USD.

Raises: Http404: The exception is raised if any error is encountered.

Returns: JsonResponse: A JSON response containing ETH and USDT values.

issue_details

issue_details(request)

Determine the Github issue keywords of the specified Github issue or PR URL.

Todo: * Modify the view to only use the Github API (remove BeautifulSoup). * Simplify the view logic.

Returns: JsonResponse: A JSON response containing the Github issue or PR keywords.

normalize_url

normalize_url(url)

Normalize the URL.

Args: url (str): The URL to be normalized.

Returns: str: The normalized URL.

UnsupportedSchemaException

UnsupportedSchemaException(self, /, *args, **kwargs)

Define unsupported schema exception handling.

UnsupportedRepoException

UnsupportedRepoException(self, /, *args, **kwargs)

Define unsupported repo exception handling.

bounty_did_change

bounty_did_change(bounty_id, new_bounty_details)

Determine whether or not the Bounty has changed.

Args: bounty_id (int): The ID of the Bounty. new_bounty_details (dict): The new Bounty raw data JSON.

Returns: bool: Whether or not the Bounty has changed. QuerySet: The old bounties queryset.

handle_bounty_fulfillments

handle_bounty_fulfillments(fulfillments, new_bounty, old_bounty)

Handle BountyFulfillment creation for new bounties.

Args: fulfillments (dict): The fulfillments data dictionary. new_bounty (dashboard.models.Bounty): The new Bounty object. old_bounty (dashboard.models.Bounty): The old Bounty object.

Returns: QuerySet: The BountyFulfillments queryset.

create_new_bounty

create_new_bounty(old_bounties, bounty_payload, bounty_details, bounty_id)

Handle new Bounty creation in the event of bounty changes.

Possible Bounty Stages: 0: Draft 1: Active 2: Dead

Returns: dashboard.models.Bounty: The new Bounty object.

process_bounty_details

process_bounty_details(bounty_details)

Process bounty details.

Args: bounty_details (dict): The Bounty details.

Raises: UnsupportedSchemaException: Exception raised if the schema is unknown or unsupported.

Returns: tuple: A tuple of bounty change data. tuple[0] (bool): Whether or not the Bounty changed. tuple[1] (dashboard.models.Bounty): The first old bounty object. tuple[2] (dashboard.models.Bounty): The new Bounty object.

get_bounty_data_for_activity

get_bounty_data_for_activity(bounty)

Get data from bounty to be saved in activity records.

Args: bounty (dashboard.models.Bounty): The Bounty object.

Returns: dict: The Bounty data represented as a dictionary.

get_fulfillment_data_for_activity

get_fulfillment_data_for_activity(fulfillment)

Get data from fulfillment to be saved in activity records.

Args: fulfillment (dashboard.models.BountyFulfillment): The BountyFulfillment.

Returns: dict: The BountyFulfillment data represented as a dictionary.

record_bounty_activity

record_bounty_activity(event_name, old_bounty, new_bounty, _fulfillment=None, override_created=None)

Records activity based on bounty changes

Args: event_name (string): the event old_bounty (dashboard.models.Bounty): The old Bounty object. new_bounty (dashboard.models.Bounty): The new Bounty object.

Raises: Exception: Log all exceptions that occur during fulfillment checks.

Returns: dashboard.Activity: The Activity object if user_profile is present or None.

record_user_action

record_user_action(event_name, old_bounty, new_bounty)

Record a user action.

Args: event_name (str): The event to be recorded. old_bounty (Bounty): The old Bounty object. new_bounty (Bounty): The new Bounty object.

Raises: Exception: Log all exceptions that occur during fulfillment checks.

is_lowball_bounty

is_lowball_bounty(bounty_value_usdt)

Determine if a bounty value is less than a threshold

Args: bounty_value_usdt (Decimal): The value of the bounty

Returns: bool: True if bounty value is less than the threshold

process_bounty_changes

process_bounty_changes(old_bounty, new_bounty)

Process Bounty changes.

Args: old_bounty (dashboard.models.Bounty): The old Bounty object. new_bounty (dashboard.models.Bounty): The new Bounty object.