コード例 #1
0
ファイル: utils.py プロジェクト: takertao2/gitcoinco-web
def mentioned_users_notification(comment):
    activity = comment.activity
    profile = comment.profile
    preview_post = truncatechars(comment.comment, 80)

    mentioned_profiles = get_profiles_from_text(comment.comment).exclude(id__in=[activity.profile_id])

    for mentioned_profile in mentioned_profiles:
        send_notification_to_user(cta_url=activity.url,
                                  cta_text='new_mention',
                                  msg_html=f'💬 <b>@{profile.handle} mentioned you</b> in comment: "{preview_post}"',
                                  to_user=mentioned_profile.user, from_user=profile.user)
コード例 #2
0
ファイル: signals.py プロジェクト: open-tribe/web
def create_notification(sender, **kwargs):
    activity = kwargs['instance']
    if activity.activity_type == 'new_tip':
        tip = activity.tip
        if tip.recipient_profile:
            send_notification_to_user(
                activity.profile.user, tip.recipient_profile.user,
                tip.receive_url, 'new_tip',
                f'<b>New Tip</b> worth {tip.value_in_usdt_now} USD ' +
                f'recieved from {tip.from_username}')

    if activity.activity_type == 'worker_applied':
        bounty = activity.bounty
        send_notification_to_user(
            activity.profile.user,
            get_user_model().objects.get(
                username__iexact=bounty.bounty_owner_github_username),
            bounty.url, 'worker_applied',
            f'<b>{activity.profile.user} applied</b> to work on {bounty.title}'
        )

    if activity.activity_type == 'worker_approved':
        bounty = activity.bounty
        send_notification_to_user(
            activity.profile.user,
            get_user_model().objects.get(
                username__iexact=activity.metadata['worker_handle']),
            bounty.url, 'worker_approved',
            f'You have been <b>approved to work on {bounty.title}</b>')

    if activity.activity_type == 'worker_rejected':
        bounty = activity.bounty
        send_notification_to_user(
            activity.profile.user,
            get_user_model().objects.get(
                username__iexact=activity.metadata['worker_handle']),
            bounty.url, 'worker_rejected',
            f'Your request to work on <b>{bounty.title} has been rejected</b>')

    if activity.activity_type == 'start_work':
        bounty = activity.bounty
        send_notification_to_user(
            activity.profile.user,
            get_user_model().objects.get(
                username__iexact=bounty.bounty_owner_github_username),
            bounty.url, 'start_work',
            f'<b>{activity.profile.user} has started work</b> on {bounty.title}'
        )

    if activity.activity_type == 'work_submitted':
        bounty = activity.bounty
        send_notification_to_user(
            activity.profile.user,
            get_user_model().objects.get(
                username__iexact=bounty.bounty_owner_github_username),
            bounty.url, 'work_submitted',
            f'<b>{activity.profile.user} has submitted work</b> for {bounty.title}'
        )

    if activity.activity_type == 'work_done':
        bounty = activity.bounty
        amount_paid = activity.metadata['new_bounty']['value_in_usdt_now']
        send_notification_to_user(
            get_user_model().objects.get(
                username__iexact=bounty.bounty_owner_github_username),
            activity.profile.user, bounty.url, 'work_done',
            f'<b>{bounty.bounty_owner_github_username}</b> has paid out ' +
            f'{amount_paid} USD for your work on {bounty.title}')

    if activity.activity_type == 'stop_work':
        bounty = activity.bounty
        send_notification_to_user(
            activity.profile.user,
            get_user_model().objects.get(
                username__iexact=bounty.bounty_owner_github_username),
            bounty.url, 'stop_work',
            f'<b>{activity.profile.user} has stopped work</b> on {bounty.title}'
        )

    if activity.activity_type == 'new_crowdfund':
        bounty = activity.bounty
        amount = activity.metadata['value_in_usdt_now']
        send_notification_to_user(
            activity.profile.user,
            get_user_model().objects.get(
                username__iexact=bounty.bounty_owner_github_username),
            bounty.url, 'new_crowdfund',
            f'A <b>crowdfunding contribution worth {amount} USD</b> has been attached for {bounty.title}'
        )

    if activity.activity_type == 'new_kudos':
        if activity.kudos_transfer and activity.kudos_transfer.recipient_profile:
            send_notification_to_user(
                activity.profile.user,
                activity.kudos_transfer.recipient_profile.user,
                activity.kudos_transfer.receive_url_for_recipient, 'new_kudos',
                f'You received a <b>new kudos from {activity.profile.user}</b>'
            )

    if activity.activity_type == 'status_update':
        text = activity.metadata['title']
        mentioned_profiles = get_profiles_from_text(text).exclude(
            id__in=[activity.profile_id])
        send_mention_notification_to_users(activity, mentioned_profiles)
コード例 #3
0
def create_notification(sender, **kwargs):
    activity = kwargs['instance']
    if activity.activity_type == 'new_tip':
        tip = activity.tip
        if tip.recipient_profile:
            send_notification_to_user(
                activity.profile.user, tip.recipient_profile.user,
                tip.receive_url, 'new_tip',
                f'<b>New Tip</b> worth {tip.value_in_usdt_now} USD ' +
                f'recieved from {tip.from_username}')

    if activity.activity_type == 'worker_applied':
        bounty = activity.bounty
        send_notification_to_user(
            activity.profile.user,
            get_user_model().objects.get(
                username__iexact=bounty.bounty_owner_github_username),
            bounty.url, 'worker_applied',
            f'<b>{activity.profile.user} applied</b> to work on {bounty.title}'
        )

    if activity.activity_type == 'worker_approved':
        bounty = activity.bounty
        send_notification_to_user(
            activity.profile.user,
            get_user_model().objects.get(
                username__iexact=activity.metadata['worker_handle']),
            bounty.url, 'worker_approved',
            f'You have been <b>approved to work on {bounty.title}</b>')

    if activity.activity_type == 'worker_rejected':
        bounty = activity.bounty
        send_notification_to_user(
            activity.profile.user,
            get_user_model().objects.get(
                username__iexact=activity.metadata['worker_handle']),
            bounty.url, 'worker_rejected',
            f'Your request to work on <b>{bounty.title} has been rejected</b>')

    if activity.activity_type == 'start_work':
        bounty = activity.bounty
        send_notification_to_user(
            activity.profile.user,
            get_user_model().objects.get(
                username__iexact=bounty.bounty_owner_github_username),
            bounty.url, 'start_work',
            f'<b>{activity.profile.user} has started work</b> on {bounty.title}'
        )

    if activity.activity_type == 'work_submitted':
        bounty = activity.bounty
        send_notification_to_user(
            activity.profile.user,
            get_user_model().objects.get(
                username__iexact=bounty.bounty_owner_github_username),
            bounty.url, 'work_submitted',
            f'<b>{activity.profile.user} has submitted work</b> for {bounty.title}'
        )

    if activity.activity_type == 'work_done':
        bounty = activity.bounty
        amount_paid = activity.metadata['new_bounty']['value_in_usdt_now']
        send_notification_to_user(
            get_user_model().objects.get(
                username__iexact=bounty.bounty_owner_github_username),
            activity.profile.user, bounty.url, 'work_done',
            f'<b>{bounty.bounty_owner_github_username}</b> has paid out ' +
            f'{amount_paid} USD for your work on {bounty.title}')

    if activity.activity_type == 'stop_work':
        bounty = activity.bounty
        send_notification_to_user(
            activity.profile.user,
            get_user_model().objects.get(
                username__iexact=bounty.bounty_owner_github_username),
            bounty.url, 'stop_work',
            f'<b>{activity.profile.user} has stopped work</b> on {bounty.title}'
        )

    if activity.activity_type == 'new_crowdfund':
        bounty = activity.bounty
        amount = activity.metadata['value_in_usdt_now']
        send_notification_to_user(
            activity.profile.user,
            get_user_model().objects.get(
                username__iexact=bounty.bounty_owner_github_username),
            bounty.url, 'new_crowdfund',
            f'A <b>crowdfunding contribution worth {amount} USD</b> has been attached for {bounty.title}'
        )

    if activity.activity_type == 'new_kudos':
        kudos_url = reverse(
            'profile_min',
            args=[activity.kudos_transfer.recipient_profile.handle, 'kudos'])

        if activity.kudos_transfer and activity.kudos_transfer.recipient_profile:
            kudos_url = activity.kudos_transfer.receive_url_for_recipient

        send_notification_to_user(
            activity.profile.user,
            activity.kudos_transfer.recipient_profile.user, kudos_url,
            'new_kudos',
            f'You received a <b>new kudos from {activity.profile.user}</b>')

    if activity.activity_type == 'status_update':
        text = activity.metadata['title']
        mentioned_profiles = get_profiles_from_text(text).exclude(
            id__in=[activity.profile_id])
        send_mention_notification_to_users(activity, mentioned_profiles)

    if activity.activity_type == 'create_ptoken':
        send_notification_to_user(
            activity.profile.user, activity.profile.user,
            activity.profile.absolute_url, 'create_ptoken',
            f'You <b>new time token {activity.ptoken.token_symbol}</b> has been created!'
        )

    if activity.activity_type == 'buy_ptoken':
        send_notification_to_user(
            activity.profile.user, activity.ptoken.token_owner_profile.user,
            activity.ptoken.token_owner_profile.absolute_url, 'buy_ptoken',
            f'New {activity.ptoken.token_symbol} <b>purchase from {activity.profile.user}</b>'
        )

    if activity.activity_type == 'accept_redemption_ptoken':
        send_notification_to_user(
            activity.ptoken.token_owner_profile.user,
            activity.redemption.redemption_requester.user,
            activity.redemption.url, 'accept_redemption_ptoken',
            f'📥 @{activity.ptoken.token_owner_profile.handle} <b>accepted</b> your request to redeem <b>{activity.redemption.total } { activity.ptoken.token_symbol }: "{activity.redemption.reason}</b>'
        )

    if activity.activity_type == 'denies_redemption_ptoken':
        redemption = activity.redemption
        if activity.redemption.redemption_state == 'denied':
            from_profile = redemption.ptoken.token_owner_profile
            to_profile = redemption.redemption_requester
            msg = f'📥 @{from_profile.handle} <b>denied</b> your request to redeem <b>{activity.redemption.total} {activity.ptoken.token_symbol}: "{activity.redemption.reason}</b>'
        else:
            if redemption.redemption_requester != redemption.canceller:
                from_profile = redemption.ptoken.token_owner_profile
                to_profile = redemption.redemption_requester
                msg = f'📥 @{from_profile.handle} <b>cancelled</b> your request to redeem <b>{activity.redemption.total} {activity.ptoken.token_symbol}: "{activity.redemption.reason}</b>'
            else:
                from_profile = redemption.redemption_requester
                to_profile = redemption.ptoken.token_owner_profile
                msg = f'📥 @{from_profile.handle} <b>cancelled</b> request to redeem <b>{activity.redemption.total} {activity.ptoken.token_symbol}: "{activity.redemption.reason}</b>'
        send_notification_to_user(from_profile.user, to_profile.user,
                                  redemption.url, 'denies_redemption_ptoken',
                                  msg)

    if activity.activity_type == 'complete_redemption_ptoken':
        redemption = activity.redemption
        send_notification_to_user(
            redemption.redemption_requester.user,
            redemption.ptoken.token_owner_profile.user, redemption.url,
            'complete_redemption_ptoken',
            f'📥 @{redemption.redemption_requester.handle} <b>completed</b> their redemption <b>{activity.redemption.total} {activity.ptoken.token_symbol}: "{activity.redemption.reason}</b>'
        )

    if activity.activity_type == 'incoming_redemption_ptoken':
        redemption = activity.redemption
        send_notification_to_user(
            redemption.ptoken.token_owner_profile.user,
            redemption.redemption_requester.user, redemption.url,
            'incoming_redemption_ptoken',
            f'Redemption "{redemption.reason}" marked as <b>ready from {redemption.ptoken.token_owner_profile}</b>'
        )