tasks.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:socialhome 作者: jaywink 项目源码 文件源码
def send_follow_notification(follower_id, followed_id):
    """Super simple you've been followed notification to a user."""
    if settings.DEBUG:
        return
    try:
        user = User.objects.get(profile__id=followed_id, is_active=True)
    except User.DoesNotExist:
        logger.warning("No active user with profile %s found for follow notification", followed_id)
        return
    try:
        follower = Profile.objects.get(id=follower_id)
    except Profile.DoesNotExist:
        logger.warning("No follower profile %s found for follow notifications", follower_id)
        return
    logger.info("send_follow_notification - Sending mail to %s", user.email)
    subject = _("New follower: %s" % follower.handle)
    context = get_common_context()
    context.update({
        "subject": subject, "actor_name": follower.name_or_handle,
        "actor_url": "%s%s" % (settings.SOCIALHOME_URL, follower.get_absolute_url()),
        "name": user.profile.name_or_handle,
    })
    send_mail(
        "%s%s" % (settings.EMAIL_SUBJECT_PREFIX, subject),
        render_to_string("notifications/follow.txt", context=context),
        settings.DEFAULT_FROM_EMAIL,
        [user.email],
        fail_silently=False,
        html_message=render_to_string("notifications/follow.html", context=context),
    )
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号