当前位置: 首页>>代码示例>>Python>>正文


Python FMSUser.email方法代码示例

本文整理汇总了Python中django_fixmystreet.fixmystreet.models.FMSUser.email方法的典型用法代码示例。如果您正苦于以下问题:Python FMSUser.email方法的具体用法?Python FMSUser.email怎么用?Python FMSUser.email使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django_fixmystreet.fixmystreet.models.FMSUser的用法示例。


在下文中一共展示了FMSUser.email方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: handle

# 需要导入模块: from django_fixmystreet.fixmystreet.models import FMSUser [as 别名]
# 或者: from django_fixmystreet.fixmystreet.models.FMSUser import email [as 别名]
    def handle(self, *args, **options):
        from django_fixmystreet.fixmystreet.models import GroupMailConfig, OrganisationEntity, ReportEventLog, UserOrganisationMembership

        # Date of yesterday (or specific date)
        if options['date']:
            YESTERDAY = datetime.datetime.strptime(options['date'], "%d/%m/%Y").date()
        else:
            YESTERDAY = datetime.date.today() - datetime.timedelta(days=1)

        logger.info('DIGEST OF NOTIFICATIONS FOR ACTVITIES OF %s' % YESTERDAY)

        # All group mail configurations with at least 1 digest config
        group_mail_configs = GroupMailConfig.objects.filter(group__type=OrganisationEntity.DEPARTMENT).filter(Q(digest_closed=True) | Q(digest_created=True) | Q(digest_inprogress=True) | Q(digest_other=True))
        logger.info('group_mail_configs %s' % group_mail_configs)

        # All group having digest config
        groups = group_mail_configs.values_list('group', flat=True)
        logger.info('groups %s' % groups)

        # All events of yesterday related to groups
        events_yesterday = ReportEventLog.objects.filter(event_at__contains=YESTERDAY, report__responsible_department__in=groups)
        logger.info('events_yesterday %s' % events_yesterday)

        for mail_config in group_mail_configs:
            group = mail_config.group

            # Returns all activities of yesterday grouped by reports where and related to group
            activities_list = events_yesterday.filter(report__responsible_department=group)

            if not activities_list:
                continue

            # Send digest to responsibles according to mail config
            recipients = mail_config.get_manager_recipients()

            logger.info('Digest of %s %s' % (group, recipients))
            logger.info('   Number of activities: %s' % activities_list.count())

            for activity in activities_list:
                logger.info('   %s %s %s' % (activity.event_at, activity.report.id, activity))

            # If NOT option send, do not send email
            if not options['send']:
                continue

            for recipient in recipients:
                # Because recipients are email and can be a user or group email, have to mock a user
                user = FMSUser()
                user.email = recipient
                user.is_pro = lambda: True
                user.last_used_language = "fr"

                # Render and send the digest by mail
                send_digest(user, activity, activities_list, YESTERDAY)
开发者ID:IMIO,项目名称:django-fixmystreet,代码行数:56,代码来源:digest_notifications_pro.py


注:本文中的django_fixmystreet.fixmystreet.models.FMSUser.email方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。