tasks.py 文件源码

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

项目:covart-web 作者: cyliang 项目源码 文件源码
def meeting_notification():
    from django.template.loader import render_to_string

    next_meeting = models.MeetingHistory.objects.all()[:1][0]

    data = {
        'meeting': next_meeting,
        'base_url': settings.BASE_URL,
    }

    if next_meeting.date - date.today() > timedelta(days=7):
        # The meeting is postponed.
        postponed_date = models.MeetingHistory.get_next_meeting_date()

        reason = ''
        skip = list(models.MeetingSkip.objects.filter(date=postponed_date))
        if len(skip) > 0 and skip[0].reason != '':
            reason = ' because of %s' % skip[0].reason

        data['postponed_date'] = postponed_date
        data['reason'] = reason

        # Notify with Slack
        async(send_slack_postponed_meeting, next_meeting, postponed_date, reason)

        template_name = 'meeting/postpone_email'
        subject = postponed_date.strftime('Group Meeting Postponed (%m/%d)')
        ret = 'Meeting postponing message sent'
    else:
        # Notify with Slack
        async(sync_meeting_with_slack, next_meeting)

        template_name = 'meeting/notify_email'
        subject = next_meeting.get_email_title()
        ret = 'Meeting notification for %s sent.' % unicode(next_meeting)

    text_body = render_to_string(template_name + '.txt', data)
    html_body = render_to_string(template_name + '.html', data)

    send_notification(
        subject=subject,
        body=text_body,
        html_body=html_body,
    )

    return ret
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号