def create_notification(bounty,
                        notification_name,
                        user,
                        notification_created,
                        string_data,
                        subject,
                        is_activity=True,
                        email=False):
    bounty_url = bounty_url_for(bounty.bounty_id, bounty.platform)
    notification = Notification.objects.create(
        notification_name=notification_name,
        user=user,
        notification_created=notification_created,
        email=email,
        dashboard=True)
    DashboardNotification.objects.create(
        notification=notification,
        string_data=string_data,
        is_activity=is_activity,
        data={'link': bounty_url},
    )
    username = bounty.user.name or 'bounty hunter'
    email_html = render_to_string('base_notification.html',
                                  context={
                                      'link': bounty_url,
                                      'username': username,
                                      'message_string': string_data
                                  })
    email_txt = 'Hello {}! \n {} \n View in app: {}'.format(
        username, string_data, bounty_url)
    if bounty.platform != 'gitcoin':
        send_email(bounty.user.email, subject, email_txt, email_html)
def create_bounty_notification(**kwargs):
    bounty = kwargs.get('bounty')
    bounty_url = bounty_url_for(
        bounty.bounty_id, bounty.platform) + kwargs.get('url_query', '')
    kwargs.update({
        'url': bounty_url,
        'platform': bounty.platform
    })
    create_notification(**kwargs)
def get_base_bounty_values(bounty):
    base_fields = narrower(bounty, ['title', 'bounty_id', 'tokenSymbol', 'tokenDecimals'])
    base_fields['total_value'] = calculate_token_quantity(bounty.fulfillmentAmount, bounty.tokenDecimals)
    base_fields['usd_price'] = Decimal(bounty.usd_price).quantize(Decimal(10) ** -2)
    base_fields['deadline'] = bounty.deadline.strftime('%m/%d/%Y')
    base_fields['token_price'] = 'Unkown Price' if not bounty.token else Decimal(bounty.token.price_usd).quantize(Decimal(10) ** -2)
    base_fields['token_lock_price'] = 'Unkown Price' if not bounty.tokenLockPrice else Decimal(bounty.tokenLockPrice).quantize(Decimal(10) ** -2)
    base_fields['link'] = bounty_url_for(bounty.bounty_id, bounty.platform)
    return base_fields
示例#4
0
    def bounty_preview_screenshot(self, platform, bounty_id, contract_version):
        if (platform == 'bounties-network' or platform == 'gitcoin') and settings.ENVIRONMENT == 'rinkeby':
            return
        if platform not in settings.PLATFORM_MAPPING and platform != 'gitcoin':
            return

        bounty = Bounty.objects.get(bounty_id=bounty_id, contract_version=contract_version)
        bounty_url = bounty_url_for(bounty_id, platform)
        image_uuid = uuid4()
        image_path = '{}/bounty_preview/{}-{}.png'.format(settings.ENVIRONMENT, str(bounty_id), image_uuid)
        image_url = 'https://assets.bounties.network/' + image_path
        sns_publish('screenshot', {'url': bounty_url, 'key': image_path})
        bounty.image_preview = image_url
        bounty.save()
示例#5
0
    def test_berlin_platform(self):
        expected = 'https://berlin.bounties.network/bounty/1'

        result = bounty_url_for(self.bounty_id, self.consensys_platform)
        self.assertEqual(result, expected)
示例#6
0
    def test_hiring_platform(self):
        expected = 'https://hiring.bounties.network/bounty/1'

        result = bounty_url_for(self.bounty_id, self.colorado_platform)
        self.assertEqual(result, expected)
示例#7
0
    def test_default_platform(self):
        expected = 'http://127.0.0.1/bounty/1'

        result = bounty_url_for(self.bounty_id)
        self.assertEqual(result, expected)
示例#8
0
    def __init__(self, **kwargs):
        bounty = kwargs['bounty']
        url = kwargs['url']
        user = kwargs['user']
        from_user = kwargs['from_user']
        notification_name = kwargs['notification_name']
        review = kwargs.get('review')
        comment = kwargs.get('comment')
        description = kwargs.get('fulfillment_description', '')
        preview_text = kwargs.get('string_data', '')

        if notification_name.__class__ != int:
            raise TypeError('notification_name must be of type int')
        elif notification_name not in Email.templates:
            raise ValueError(
                'notification_name {} must be a valid notification'.format(
                    notification_name))
        if bounty.__class__ != Bounty:
            raise TypeError('bounty must be of type Bounty')

        issuer = bounty.user

        token_decimals = Context(prec=6).create_decimal
        usd_decimals = Context(prec=3).create_decimal
        remaining = token_decimals(bounty.calculated_balance).normalize()
        token_amount = token_decimals(
            bounty.calculated_fulfillmentAmount).normalize()

        if len(description) > self.max_description_length:
            # Cut off at the closest word after the limit
            description = wrap(
                description,
                self.max_description_length
            )[0] + ' ...'

        title = bounty.title
        if len(title) > self.max_title_length:
            # Cut off at the closest word after the limit
            title = wrap(title, self.max_title_length)[0] + ' ...'

        if not url or len(url) == 0:
            url = bounty_url_for(bounty.bounty_id, bounty.platform)

        remaining_submissions = 0

        if notification_name == constants.BOUNTY_EXPIRED:
            remaining_submissions = Fulfillment.objects.filter(
                bounty_id=bounty.id,
                accepted=False,
            ).all().count()

        remaining_usd = ' unknown'
        if bounty.tokenLockPrice:
            remaining_usd = usd_decimals(
                remaining * usd_decimals(bounty.tokenLockPrice)).normalize()
        elif bounty.token and bounty.token.price_usd:
            remaining_usd = usd_decimals(
                remaining * usd_decimals(bounty.token.price_usd)).normalize()

        added_amount = 0
        if notification_name == constants.CONTRIBUTION_ADDED:
            inputs = kwargs['inputs']
            added_amount = token_decimals(calculate_token_value(
                int(inputs['value']), bounty.tokenDecimals)).normalize()

        rating_url = url
        if notification_name == constants.FULFILLMENT_ACCEPTED_FULFILLER:
            rating_url = '{}?fulfillment_id={}&rating=true'.format(
                url, kwargs['fulfillment_id'])

        self.__dict__.update({
            'bounty': bounty,
            'bounty_title': title,
            'url': url,
            'preferences_link': 'https://{}bounties.network/settings'.format(
                '' if ENVIRONMENT == 'production' else 'staging.'),
            'notification_name': notification_name,
            'usd_amount': usd_decimals(bounty.usd_price).normalize(),
            'token_amount': token_amount,
            'token': bounty.tokenSymbol,
            'bounty_categories': Email.render_categories(
                bounty.data_categories),
            'token_amount_remaining': remaining,
            'usd_amount_remaining': remaining_usd,
            'added_amount': added_amount,
            'remaining_submissions': remaining_submissions,
            'fulfillment_description': description,
            'issuer_name': issuer and issuer.name,
            'issuer_address': issuer and shorten_address(
                issuer.public_address),
            'issuer_profile_image': (
                issuer and issuer.profile_image or default_image
            ),
            'issuer_address_link': issuer and profile_url_for(
                issuer.public_address, bounty.platform),
            'user_name': user and user.name,
            'user_address': user and shorten_address(user.public_address),
            'user_profile_image': (
                user and user.profile_image or default_image
            ),
            'user_address_link': user and profile_url_for(
                user.public_address, bounty.platform),
            'from_user_name': from_user and from_user.name,
            'from_user_address': from_user and shorten_address(
                from_user.public_address),
            'from_user_profile_image': (
                from_user and from_user.profile_image or default_image
            ),
            'from_user_address_link': from_user and profile_url_for(
                from_user.public_address, bounty.platform),
            'from_user_email': from_user and from_user.email,
            'review': review and review.review,
            'rating': review and '{}/5'.format(review.rating),
            'rating_color': review and Email.rating_color(review.rating),
            'comment': comment and comment.text,
            'MC_PREVIEW_TEXT': preview_text,
            'rating_url': rating_url
        })
示例#9
0
    def __init__(self, **kwargs):
        bounty = kwargs['bounty']
        url = kwargs['url']
        user = kwargs['user']
        issuer = kwargs['issuer']
        from_user = kwargs['from_user']
        notification_name = kwargs['notification_name']
        review = kwargs.get('review')
        comment = kwargs.get('comment')
        description = kwargs.get('fulfillment_description', '')
        preview_text = kwargs.get('string_data', '')
        application_message = kwargs.get('application_message', '')
        rejection_message = kwargs.get('rejection_message', '')

        if notification_name.__class__ != int:
            raise TypeError('notification_name must be of type int')
        elif notification_name not in Email.templates:
            raise ValueError(
                'notification_name {} must be a valid notification'.format(
                    notification_name))
        if bounty.__class__ != Bounty:
            raise TypeError('bounty must be of type Bounty')

        remaining = token_decimals(bounty.calculated_balance)
        token_amount = token_decimals(bounty.calculated_fulfillment_amount)

        if len(description) > self.max_description_length:
            # Cut off at the closest word after the limit
            description = wrap(description,
                               self.max_description_length)[0] + ' ...'

        title = bounty.title
        if len(title) > self.max_title_length:
            # Cut off at the closest word after the limit
            title = wrap(title, self.max_title_length)[0] + ' ...'

        if not url or len(url) == 0:
            url = bounty_url_for(bounty.id, bounty.platform)

        remaining_submissions = 0

        if (notification_name == constants.BOUNTY_EXPIRED
                or notification_name == constants.CONTRIBUTION_RECEIVED
                or notification_name == constants.CONTRIBUTION_ADDED):
            remaining_submissions = Fulfillment.objects.filter(
                bounty_id=bounty.id,
                accepted=False,
            ).all().count()
        total_submissions = Fulfillment.objects.filter(
            bounty_id=bounty.id,
            accepted=False,
        ).all().count()
        submissions = ''
        if total_submissions == 1:
            submissions = '{} submission'.format(total_submissions)
        else:
            submissions = '{} submissions'.format(total_submissions)

        remaining_usd = ' unknown'
        if bounty.token_lock_price:
            remaining_usd = usd_decimals(remaining *
                                         usd_decimals(bounty.token_lock_price))
        elif bounty.token and bounty.token.price_usd:
            remaining_usd = usd_decimals(remaining *
                                         usd_decimals(bounty.token.price_usd))

        added_amount = 0
        if (notification_name == constants.CONTRIBUTION_RECEIVED
                or notification_name == constants.CONTRIBUTION_ADDED):
            amount = kwargs['amount']
            added_amount = token_decimals(
                calculate_token_value(int(Decimal(amount)),
                                      bounty.token_decimals))

        rating_url = url
        if notification_name == constants.FULFILLMENT_ACCEPTED_FULFILLER:
            rating_url = '{}?fulfillment_id={}&rating=true'.format(
                url, kwargs['fulfillment_id'])

        user_address_link = (user and profile_url_for(user.public_address,
                                                      bounty.platform))

        ratings = None
        rating_link = None
        if notification_name == constants.RATING_RECEIVED:
            user_reviewees = user.reviewees.filter(platform=bounty.platform)
            rating_link = user_address_link + '?reviews=true'

            if user.public_address == issuer.public_address:
                # Rating for the issuer from the fulfiller
                ratings = user_reviewees.filter(issuer_review__isnull=False)
            else:
                # Rating for the fulfiller from the issuer
                ratings = user_reviewees.filter(
                    fulfillment_review__isnull=False)
                rating_link += '&fulfiller=true'

        rating_count = ratings and ratings.count() or 0
        average_rating = ratings and ratings.aggregate(
            Avg('rating')).get('rating__avg') or 0

        self.__dict__.update({
            'bounty':
            bounty,
            'bounty_title':
            title,
            'url':
            url,
            'preferences_link':
            'https://{}bounties.network/settings'.format(
                '' if ENVIRONMENT == 'production' else 'staging.'),
            'notification_name':
            notification_name,
            'usd_amount':
            usd_decimals(bounty.usd_price),
            'token_amount':
            token_amount,
            'token':
            bounty.token_symbol,
            'token_amount_remaining':
            remaining,
            'usd_amount_remaining':
            remaining_usd,
            'added_amount':
            added_amount,
            'remaining_submissions':
            remaining_submissions,
            'fulfillment_description':
            description,
            'application_message':
            application_message,
            'issuer_name':
            issuer and issuer.name,
            'issuer_address':
            issuer and shorten_address(issuer.public_address),
            'issuer_profile_image': (issuer and issuer.small_profile_image_url
                                     or default_image),
            'issuer_address_link':
            issuer and profile_url_for(issuer.public_address, bounty.platform),
            'user_name':
            user and user.name,
            'user_address':
            user and shorten_address(user.public_address),
            'user_profile_image': (user and user.small_profile_image_url
                                   or default_image),
            'user_address_link':
            user_address_link,
            'from_user_name':
            from_user and from_user.name,
            'from_user_address':
            from_user and shorten_address(from_user.public_address),
            'from_user_profile_image':
            (from_user and from_user.small_profile_image_url or default_image),
            'from_user_address_link':
            from_user
            and profile_url_for(from_user.public_address, bounty.platform),
            'from_user_email':
            from_user and from_user.email,
            'review':
            review and review.review,
            'rating':
            review and '{}/5'.format(review.rating),
            'rating_color':
            review and Email.rating_color(review.rating),
            'comment':
            comment and comment.text,
            'MC_PREVIEW_TEXT':
            preview_text,
            'rating_url':
            rating_url,
            'average_rating':
            usd_decimals(average_rating),
            'rating_count':
            rating_count,
            'rating_link':
            rating_link,
            'contribute_url':
            url + '?contribute=true',
            'submissions':
            submissions,
            'rejection_message':
            rejection_message
        })
示例#10
0
 def clear_cache(self, platform, bounty_id):
     bounty_url = bounty_url_for(bounty_id, platform)
     sns_publish('ssrcache', {'url': bounty_url})