コード例 #1
0
ファイル: rh_models.py プロジェクト: ratan325/regluit
def notify_rh(sender, created, instance, **kwargs):
    # don't notify for tests or existing rights holders
    if 'example.org' in instance.email or instance.id < 47:
        return
    try:
        (rights, new_rights) = User.objects.get_or_create(
            email='*****@*****.**',
            defaults={'username': '******'})
    except:
        rights = None
    user_list = (instance.owner, rights)
    if created:
        notification.send(user_list, "rights_holder_created", {
            'rights_holder': instance,
        })
    elif instance.approved:
        agreement = strip_tags(
            render_to_string('accepted_agreement.html', {
                'rights_holder': instance,
            }))
        signature = ''
        notification.send(
            user_list, "rights_holder_accepted", {
                'rights_holder': instance,
                'agreement': agreement,
                'signature': signature,
            })
        for claim in instance.claim.filter(status='pending'):
            claim.status = 'active'
            claim.save()
    from regluit.core.tasks import emit_notifications
    emit_notifications.delay()
コード例 #2
0
def update_account_status(all_accounts=True, send_notice_on_change_only=True):
    """update the status of all Accounts
    
        By default, send notices only if the status is *changing*.  Set send_notice_on_change_only = False to
        send notice based on new_status regardless of old status.  (Useful for initialization)
    """
    errors = []

    if all_accounts:
        accounts_to_calc = Account.objects.all()
    else:
        # active accounts with expiration dates from this month earlier
        today = date_today()
        year = today.year
        month = today.month
        accounts_to_calc = Account.objects.filter(
            Q(date_deactivated__isnull=True)).filter(
                (Q(card_exp_year__lt=year)
                 | Q(card_exp_year=year, card_exp_month__lte=month)))

    for account in accounts_to_calc:
        try:
            account.update_status(
                send_notice_on_change_only=send_notice_on_change_only)
        except Exception as e:
            errors.append(e)

    # fire off notices

    from regluit.core.tasks import emit_notifications
    emit_notifications.delay()

    return errors
コード例 #3
0
def handle_wishlist_near_deadline(campaign, **kwargs):
    """
    send two groups - one the nonpledgers, one the pledgers
    set the pledged flag differently in the context
    """
    pledgers = campaign.ungluers()['all']
    nonpledgers = campaign.work.wished_by().exclude(
        id__in=[p.id for p in pledgers])

    notification.send(
        pledgers, "wishlist_near_deadline", {
            'campaign': campaign,
            'domain': settings.BASE_URL_SECURE,
            'pledged': True,
        }, True)

    notification.send(
        nonpledgers, "wishlist_near_deadline", {
            'campaign': campaign,
            'domain': settings.BASE_URL_SECURE,
            'pledged': False,
        }, True)

    from regluit.core.tasks import emit_notifications
    emit_notifications.delay()
コード例 #4
0
def notify_comment(comment, request, **kwargs):
    logger.info('comment %s notifying' % comment.pk)
    other_commenters = User.objects.filter(
        comment_comments__content_type=comment.content_type,
        comment_comments__object_pk=comment.object_pk).distinct().exclude(
            id=comment.user_id)
    all_wishers = comment.content_object.wished_by().exclude(
        id=comment.user_id)
    other_wishers = all_wishers.exclude(id__in=other_commenters)
    domain = Site.objects.get_current().domain
    if comment.content_object.last_campaign(
    ) and comment.user in comment.content_object.last_campaign().managers.all(
    ):
        #official
        notification.queue(all_wishers, "wishlist_official_comment", {
            'comment': comment,
            'domain': domain
        }, True)
    else:
        notification.send(other_commenters,
                          "comment_on_commented", {'comment': comment},
                          True,
                          sender=comment.user)
        notification.send(other_wishers,
                          "wishlist_comment", {'comment': comment},
                          True,
                          sender=comment.user)
    from regluit.core.tasks import emit_notifications
    emit_notifications.delay()
コード例 #5
0
ファイル: signals.py プロジェクト: slimlime/regluit
def handle_credit_balance(sender, amount=0, **kwargs):
    notification.queue([sender.user], "pledge_gift_credit", {
        'user': sender.user,
        'amount': amount,
        'minus_amount': -amount
    }, True)
    from regluit.core.tasks import emit_notifications
    emit_notifications.delay()
コード例 #6
0
def notify_supporter_message(sender, work, supporter, msg, **kwargs):
    """send notification in of supporter message"""
    logger.info('received supporter_message signal for {0}'.format(supporter))

    notification.send([supporter], "wishlist_message", {
        'work': work,
        'msg': msg
    }, True, sender)
    from regluit.core.tasks import emit_notifications
    emit_notifications.delay()
コード例 #7
0
def notify_successful_campaign(campaign, **kwargs):
    """send notification in response to successful campaign"""
    logger.info('received successful_campaign signal for {0}'.format(campaign))
    # supporters and staff -- though it might be annoying for staff to be getting all these notices!
    staff = User.objects.filter(is_staff=True)
    supporters = (User.objects.get(id=k) for k in campaign.supporters())

    notification.send(itertools.chain(staff, supporters),
                      "wishlist_successful", {'campaign': campaign}, True)
    from regluit.core.tasks import emit_notifications
    emit_notifications.delay()
コード例 #8
0
def handle_you_have_pledged(sender, transaction=None, **kwargs):
    if transaction == None:
        return

    #give user a badge
    if not transaction.anonymous:
        transaction.user.profile.reset_pledge_badge()

    notification.send([transaction.user], "pledge_you_have_pledged",
                      {'transaction': transaction}, True)
    from regluit.core.tasks import emit_notifications
    emit_notifications.delay()
コード例 #9
0
def handle_wishlist_added(supporter, work, **kwargs):
    """send notification to confirmed rights holder when someone wishes for their work"""
    claim = work.claim.filter(status="active")
    if claim:
        notification.send(
            [claim[0].user], "new_wisher", {
                'supporter': supporter,
                'work': work,
                'base_url': settings.BASE_URL_SECURE,
            }, True)

        from regluit.core.tasks import emit_notifications
        emit_notifications.delay()
コード例 #10
0
def handle_transaction_failed(sender, transaction=None, **kwargs):
    if transaction is None or transaction.campaign == None or transaction.campaign.type == THANKS:
        # no need to nag a failed THANKS or DONATION transaction
        return

    # window for recharging
    recharge_deadline = transaction.deadline_or_now + datetime.timedelta(
        settings.RECHARGE_WINDOW)

    notification.send([transaction.user], "pledge_failed", {
        'transaction': transaction,
        'recharge_deadline': recharge_deadline
    }, True)
    from regluit.core.tasks import emit_notifications
    emit_notifications.delay()
コード例 #11
0
def handle_pledge_modified(sender,
                           transaction=None,
                           up_or_down=None,
                           **kwargs):
    # we need to know if pledges were modified up or down because Amazon handles the
    # transactions in different ways, resulting in different user-visible behavior;
    # we need to set expectations appropriately
    # up_or_down is 'increased', 'decreased', or 'canceled'
    if transaction == None or up_or_down == None:
        return
    if up_or_down == 'canceled':
        transaction.user.profile.reset_pledge_badge()
    notification.send([transaction.user], "pledge_status_change", {
        'transaction': transaction,
        'up_or_down': up_or_down
    }, True)
    from regluit.core.tasks import emit_notifications
    emit_notifications.delay()
コード例 #12
0
ファイル: tasks.py プロジェクト: slimlime/regluit
        accounts_to_calc = Account.objects.filter(
            Q(date_deactivated__isnull=True)).filter(
                (Q(card_exp_year__lt=year)
                 | Q(card_exp_year=year, card_exp_month__lte=month)))

    for account in accounts_to_calc:
        try:
            account.update_status(
                send_notice_on_change_only=send_notice_on_change_only)
        except Exception, e:
            errors.append(e)

    # fire off notices

    from regluit.core.tasks import emit_notifications
    emit_notifications.delay()

    return errors


# task run roughly 8 days ahead of card expirations
@task
def notify_expiring_accounts():
    expiring_accounts = Account.objects.filter(status='EXPIRING')
    for account in expiring_accounts:
        notification.send_now([account.user], "account_expiring", {
            'user': account.user,
            'site': Site.objects.get_current()
        }, True)

コード例 #13
0
def handle_transaction_charged(sender, transaction=None, **kwargs):
    if transaction == None:
        return
    transaction._current_total = None
    context = {
        'transaction': transaction,
        'current_site': Site.objects.get_current()
    }
    if not transaction.campaign:
        if transaction.user:
            notification.send([transaction.user], "donation", context, True)
        elif transaction.receipt:
            from regluit.core.tasks import send_mail_task
            message = render_to_string("notification/donation/full.txt",
                                       context)
            send_mail_task.delay('unglue.it donation confirmation', message,
                                 '*****@*****.**', [transaction.receipt])
    elif transaction.campaign.type is REWARDS:
        notification.send([transaction.user], "pledge_charged", context, True)
    elif transaction.campaign.type is BUY2UNGLUE:
        # provision the book
        Acq = apps.get_model('core', 'Acq')
        if transaction.offer.license == LIBRARY:
            library = Library.objects.get(id=transaction.extra['library_id'])
            new_acq = Acq.objects.create(user=library.user,
                                         work=transaction.campaign.work,
                                         license=LIBRARY)
            if transaction.user_id != library.user_id:  # don't put it on reserve if purchased by the library
                reserve_acq = Acq.objects.create(
                    user=transaction.user,
                    work=transaction.campaign.work,
                    license=RESERVE,
                    lib_acq=new_acq)
                reserve_acq.expire_in(datetime.timedelta(hours=2))
            copies = int(transaction.extra.get('copies', 1))
            while copies > 1:
                Acq.objects.create(user=library.user,
                                   work=transaction.campaign.work,
                                   license=LIBRARY)
                copies -= 1
        else:
            if transaction.extra.get('give_to', False):
                # it's a gift!
                Gift = apps.get_model('core', 'Gift')
                giftee = Gift.giftee(transaction.extra['give_to'],
                                     str(transaction.id))
                new_acq = Acq.objects.create(user=giftee,
                                             work=transaction.campaign.work,
                                             license=transaction.offer.license)
                gift = Gift.objects.create(acq=new_acq,
                                           message=transaction.extra.get(
                                               'give_message', ''),
                                           giver=transaction.user,
                                           to=transaction.extra['give_to'])
                context['gift'] = gift
                notification.send([giftee], "purchase_gift", context, True)
            else:
                new_acq = Acq.objects.create(user=transaction.user,
                                             work=transaction.campaign.work,
                                             license=transaction.offer.license)
        transaction.campaign.update_left()
        notification.send([transaction.user], "purchase_complete", context,
                          True)
        from regluit.core.tasks import watermark_acq
        watermark_acq.delay(new_acq.id)
        if transaction.campaign.cc_date < date_today():
            transaction.campaign.update_status(send_notice=True)
    elif transaction.campaign.type is THANKS:
        if transaction.user:
            Acq = apps.get_model('core', 'Acq')
            new_acq = Acq.objects.create(user=transaction.user,
                                         work=transaction.campaign.work,
                                         license=THANKED)
            notification.send([transaction.user], "purchase_complete", context,
                              True)
        elif transaction.receipt:
            from regluit.core.tasks import send_mail_task
            message = render_to_string(
                "notification/purchase_complete/full.txt", context)
            send_mail_task.delay('unglue.it transaction confirmation', message,
                                 '*****@*****.**', [transaction.receipt])
    from regluit.core.tasks import emit_notifications
    emit_notifications.delay()