本文整理汇总了Python中apps.fixmystreet.models.FMSUser.last_used_language方法的典型用法代码示例。如果您正苦于以下问题:Python FMSUser.last_used_language方法的具体用法?Python FMSUser.last_used_language怎么用?Python FMSUser.last_used_language使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类apps.fixmystreet.models.FMSUser
的用法示例。
在下文中一共展示了FMSUser.last_used_language方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
# 需要导入模块: from apps.fixmystreet.models import FMSUser [as 别名]
# 或者: from apps.fixmystreet.models.FMSUser import last_used_language [as 别名]
def handle(self, *args, **options):
from apps.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)