本文整理汇总了Python中activity.Activity.create方法的典型用法代码示例。如果您正苦于以下问题:Python Activity.create方法的具体用法?Python Activity.create怎么用?Python Activity.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类activity.Activity
的用法示例。
在下文中一共展示了Activity.create方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_follower
# 需要导入模块: from activity import Activity [as 别名]
# 或者: from activity.Activity import create [as 别名]
def add_follower(cls, leader, follower):
# TODO: expand to handle more than 5000 followers, using extra entities
follower_id = follower.key().id() # TickUser.get_by_user_id(follower.user_id(),keys_only=True).id()
leader_id = leader.key().id()
check = cls.all(keys_only=True).ancestor(leader).filter("followers_ids =", follower_id).get()
if not check:
entity = cls.all().ancestor(leader).filter("leader_id =", leader_id).get()
if entity:
entity.follower_ids.append(follower_id)
index = entity.get_follow_index()
index.add_followers(follower.all_user_ids)
index.put()
entity.put()
else:
new_entity = cls(parent=leader, leader_id=leader_id, follower_ids=[follower_id])
new_entity.put()
new_index = FollowIndex(parent=new_entity)
new_index.add_leaders(leader.all_user_ids)
new_index.add_followers(follower.all_user_ids)
new_index.put()
from activity import Activity
Activity.create(
"<actor>|began following|<target>", actor=follower, target=leader, extra_recipients=[leader]
)
return True
else:
return False
示例2: remove_follower
# 需要导入模块: from activity import Activity [as 别名]
# 或者: from activity.Activity import create [as 别名]
def remove_follower(leader, follower):
follower_id = follower.key().id()
existing = (
Follow.all()
.ancestor(leader)
.filter("leader_id =", leader.key().id())
.filter("follower_ids =", follower_id)
.get()
)
if not existing:
return False
existing.follower_ids.remove(follower_id)
existing.put()
# do dependent index
index = existing.get_follow_index()
for user_id in follower.all_user_ids:
index.remove_follower(user_id)
index.put()
from activity import Activity
Activity.create("<actor>|stopped following|<target>", actor=follower, target=leader, extra_recipients=[leader])
return True