Esempio n. 1
0
 def profile_preview_screenshot(self, user_id):
     user = User.objects.get(id=user_id)
     profile_url = profile_url_for(user.public_address)
     image_uuid = uuid4()
     image_path = '{}/profile_preview/{}-{}.png'.format(settings.ENVIRONMENT, user.public_address, image_uuid)
     image_url = 'https://assets.bounties.network/' + image_path
     user.page_preview = image_url
     user.save()
     sns_publish('screenshot', {'url': profile_url, 'key': image_path})
def create_rating_notification(**kwargs):
    bounty = kwargs.get('bounty')
    user = kwargs.get('user')
    issuer = bounty.user

    reviewee = 'fulfiller'
    if user.public_address == issuer.public_address:
        # Rating for the issuer from the fulfiller
        reviewee = 'issuer'

    profile_url = profile_url_for(user.public_address)
    kwargs.update({
        'url': profile_url + '?reviews=true&{}=true'.format(reviewee),
        'platform': bounty.platform
    })
    create_notification(**kwargs)
def update_dash_notification(issuer_address, user, dash):
    reviewee = 'fulfiller'

    print()
    print('running update_dash_notification with {} {} {}'.format(
        issuer_address, user, dash))
    print()

    if user.public_address == issuer_address:
        # Rating for the issuer from the fulfiller
        reviewee = 'issuer'

    profile_url = profile_url_for(user.public_address)
    url = profile_url + '?reviews=true&{}=true'.format(reviewee)
    print('changing dash notification from:')
    print(dash.__dict__)
    print()
    dash.data['link'] = url
    print('to:')
    print(dash.__dict__)
    print()

    print('NOT UPDATING (uncomment here to actually update)')
Esempio n. 4
0
def create_profile_updated_notification(*args, **kwargs):
    profile_url = profile_url_for(kwargs.get('user').public_address)
    kwargs.update({'url': profile_url})
    create_notification(**kwargs)
Esempio n. 5
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
        })
Esempio n. 6
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
        })