本文整理汇总了Python中activity.models.Activity.target_user方法的典型用法代码示例。如果您正苦于以下问题:Python Activity.target_user方法的具体用法?Python Activity.target_user怎么用?Python Activity.target_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类activity.models.Activity
的用法示例。
在下文中一共展示了Activity.target_user方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: follow_handler
# 需要导入模块: from activity.models import Activity [as 别名]
# 或者: from activity.models.Activity import target_user [as 别名]
def follow_handler(sender, **kwargs):
rel = kwargs.get("instance", None)
if not isinstance(rel, Relationship):
return
user_subject = _("%(name)s is following you on Drumbeat!" % {"name": rel.source.name})
project_subject = _("%(name)s is following your project on Drumbeat!" % {"name": rel.source.name})
activity = Activity(actor=rel.source, verb="http://activitystrea.ms/schema/1.0/follow")
subject = _(u"%(name)s is now following")
if rel.target_user:
activity.target_user = rel.target_user
user = rel.target_user
pref_key = "no_email_new_follower"
subject = user_subject
else:
activity.project = rel.target_project
user = rel.target_project.created_by
pref_key = "no_email_new_project_follower"
subject = project_subject
activity.save()
preferences = AccountPreferences.objects.filter(user=user)
for pref in preferences:
if pref.value and pref.key == pref_key:
return
body = render_to_string(
"relationships/emails/new_follower.txt", {"user": rel.source, "project": rel.target_project}
)
SendUserEmail.apply_async((user, subject, body))
示例2: follow_handler
# 需要导入模块: from activity.models import Activity [as 别名]
# 或者: from activity.models.Activity import target_user [as 别名]
def follow_handler(sender, **kwargs):
rel = kwargs.get('instance', None)
created = kwargs.get('created', False)
if not created or not isinstance(rel, Relationship):
return
activity = Activity(actor=rel.source,
verb='http://activitystrea.ms/schema/1.0/follow')
receipts = []
ulang=get_language()
subject = {}
body = {}
if rel.target_user:
activity.target_user = rel.target_user
for l in settings.SUPPORTED_LANGUAGES:
activate(l[0])
subject[l[0]] = ugettext('%(display_name)s is following you on P2PU!') % {
'display_name': rel.source.display_name,
}
preferences = AccountPreferences.objects.filter(user=rel.target_user)
for pref in preferences:
if pref.value and pref.key == 'no_email_new_follower':
break
else:
receipts.append(rel.target_user)
else:
activity.project = rel.target_project
for l in settings.SUPPORTED_LANGUAGES:
activate(l[0])
subject[l[0]] = ugettext('%(display_name)s is following %(project)s on P2PU!') % {
'display_name': rel.source.display_name, 'project': rel.target_project }
for organizer in rel.target_project.organizers():
if organizer.user != rel.source:
preferences = AccountPreferences.objects.filter(user=organizer.user)
for pref in preferences:
if pref.value and pref.key == 'no_email_new_project_follower':
break
else:
receipts.append(organizer.user)
activity.save()
for l in settings.SUPPORTED_LANGUAGES:
activate(l[0])
body[l[0]] = render_to_string("relationships/emails/new_follower.txt", {
'user': rel.source,
'project': rel.target_project,
'domain': Site.objects.get_current().domain,
})
activate(ulang)
for user in receipts:
pl = user.preflang or settings.LANGUAGE_CODE
SendUserEmail.apply_async((user, subject[pl], body[pl]))
示例3: follow_handler
# 需要导入模块: from activity.models import Activity [as 别名]
# 或者: from activity.models.Activity import target_user [as 别名]
def follow_handler(sender, **kwargs):
rel = kwargs.get('instance', None)
created = kwargs.get('created', False)
if not created or not isinstance(rel, Relationship):
return
user_subject = ugettext('%(display_name)s is following you on P2PU!') % {
'display_name': rel.source.display_name,
}
project_subject = ugettext('%(display_name)s is following %(project)s on P2PU!') % {
'display_name': rel.source.display_name,
'project': rel.target_project,
}
activity = Activity(actor=rel.source,
verb='http://activitystrea.ms/schema/1.0/follow')
subject = ugettext('%(display_name)s is now following')
if rel.target_user:
activity.target_user = rel.target_user
user = rel.target_user
pref_key = 'no_email_new_follower'
subject = user_subject
else:
activity.project = rel.target_project
user = rel.target_project.created_by
pref_key = 'no_email_new_project_follower'
subject = project_subject
activity.save()
preferences = AccountPreferences.objects.filter(user=user)
for pref in preferences:
if pref.value and pref.key == pref_key:
return
body = render_to_string("relationships/emails/new_follower.txt", {
'user': rel.source,
'project': rel.target_project,
'domain': Site.objects.get_current().domain,
})
SendUserEmail.apply_async((user, subject, body))