@shared_task()
def send_daily_digest_notification(user_id):
    notifications = Notification.objects.filter(
        recipient_id=user_id,
        consumed=False,
        # Only send notifications for approved messages, otherwise leave the
        # messages pending
        message__status='approved',
        subscription__period='daily'
    ).select_related(
        'recipient',
        'message',
        'message__thread',
        'message__thread__group',
        'message__thread__group__group'
    ).order_by('-message__thread', '-message__pk')

    # To reduce the number of `count` and `exists` queries, do the count once
    # and base as much logic around that count as possible.
    total_notifications = notifications.count()

    if not total_notifications:
        return
    recipient = notifications[0].recipient

    context = {
        'notifications': notifications,
        'recipient': recipient,
        'email': recipient.email
    }
    text = render_to_string('notifications/email/email_digest.txt', context)
    html = render_to_string('notifications/email/email_digest.html', context)

    subject = u'Your {brand} {day} Digest - {num} New {word}'.format(
        brand=settings.BRAND_TITLE,
        day=now().strftime('%A'),
        num=total_notifications,
        word=ngettext('Message', 'Messages', total_notifications)
    )

    send_email(
        email=recipient.email,
        from_email=settings.DEFAULT_FROM_EMAIL,
        subject=subject,
        text=text,
        html=html
    )

    notifications.update(consumed=True)
Handler for GET requests.
dataset/ETHPy150Open ofa/connect/open_connect/notifications/tasks.py/send_daily_digest_notification--crossover with--dataset/ETHPy150Open AppScale/appscale/AppDashboard/dashboard.py/NewUserPage.get