本文整理汇总了Python中models.Activity.add_to_set方法的典型用法代码示例。如果您正苦于以下问题:Python Activity.add_to_set方法的具体用法?Python Activity.add_to_set怎么用?Python Activity.add_to_set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Activity
的用法示例。
在下文中一共展示了Activity.add_to_set方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: new_activity
# 需要导入模块: from models import Activity [as 别名]
# 或者: from models.Activity import add_to_set [as 别名]
def new_activity(aid):
try:
activity = Activity.objects.get(id = aid)
if activity.is_cancelled():
return
except Activity.DoesNotExist:
return
not_master = activity.status != Activity.MASTER
interests_to_notify = activity.interest_notified
follower_ids_to_notify = activity.followers_notified
add_activity_notification(follower_ids_to_notify, aid)
logger.info('new_activity aid:%s status:%s interests_to_notify:%s' % (str(activity.id), activity.status, str(interests_to_notify)))
logger.info('new_activity aid:%s status:%s followers_to_notify:%s' % (str(activity.id), activity.status, str(follower_ids_to_notify)))
if not_master:
suggester = User.objects.get(_id = activity.suggester_id)
logger.info('new_activity aid:%s suggester:%s' % (str(activity.id), str(suggester)))
# suggester_friend_store = suggester.get_friend_store()
# following_ids = suggester.following_me
# friend_ids = suggester_friend_store.get_friend_ids()
# fof_ids = FriendOfFriendStore.get_fof_ids_raw(suggester._id) if activity.visibility == 'fof' else []
# interests_to_notify = col_get(USER_, {"_id" : {"$in" : fof_ids + friend_ids }, "interest" : activity.keyword, "network" : suggester.network}, list_=True)
# followers_to_notify = col_get(USER_, {"_id" : {"$in" : following_ids }, "network" : suggester.network}, list_=True)
pic_url = get_fb_profile_pic_link(suggester._id)
# logger.info('new_activity aid:%s %s interests to notify from friends:%s fofs:%s' % (str(activity.id), str(len(interests_to_notify)), str(friend_ids), str(fof_ids)))
# logger.info('new_activity aid:%s followers:%s' % (str(activity.id), str(followers_to_notify)))
message = [
'@' + suggester.name,
' is keen to #',
activity.keyword,
'. Join ',
'@' + suggester.name
]
else:
# logger.info('new_activity aid:%s status==master' % str(activity.id))
# interests_to_notify = []
# followers_to_notify = col_get(USER_, {"interest" : activity.keyword}, list_=True)
# logger.info('new_activity aid:%s followers:%s' % (str(activity.id), str(followers_to_notify)))
message = [
'Join #',
activity.keyword,
' : "',
activity.text,
'"'
]
pic_url = ''
interests_to_notify = col_get(USER_, {"_id" : {"$in" : interests_to_notify }}, list_=True)
followers_to_notify = col_get(USER_, {"_id" : {"$in" : follower_ids_to_notify }}, list_=True)
store_data = {
'uid' : suggester._id if not_master else '',
'aid' : activity.id,
'pic' : pic_url
}
logger.info('new_activity aid:%s status:%s message:%s' % (str(activity.id), activity.status, str(message)))
android_ids = []
apple_ids = []
badge_nums = []
for follower in followers_to_notify:
android_ids.append(follower.get('device_gcm_token'))
apple_ids.append(follower.get('device_pns_token'))
badge_num = add_notification(follower['_id'], settings.NOTIF_ACTIVITY_NEW, message, pic_url, store_data)
badge_nums.append(badge_num)
Activity.add_to_set(activity.id, 'followers_notified', follower['_id'])
data = {
'title' : suggester.name if not_master else 'Join #' + activity.keyword,
'msg' : activity.text,
'aid' : activity.id,
'ticker' : 'New activity',
'uid' : suggester._id if not_master else '',
# 'type' : settings.NOTIF_FOLLOWING_POST,
'type' : settings.NOTIF_ACTIVITY_NEW,
}
i_data = {
'msg' : suggester.name + ' posted: "' + activity.text + '"' if not_master else 'Join #' + activity.keyword,
'aid' : activity.id,
'uid' : suggester._id,
'type' : settings.NOTIF_ACTIVITY_NEW,
}
follower_androids = set(android_ids)
follower_apples = set(apple_ids)
logger.info('new_activity aid:%s sending to followers data:%s, android_ids:%s, apple_ids:%s' % (str(activity.id), str(data), str(android_ids), str(apple_ids)))
send(data, android_ids, apple_ids, badge_nums, i_data=i_data)
# android_ids = set()
# apple_ids = set()
# badge_nums = []
#
# if not_master:
# message = [
# '@' + suggester.name,
# ' posted a snip with #',
# activity.keyword,
# '. Join ',
# '@' + suggester.name
# ]
#.........这里部分代码省略.........