本文整理汇总了Python中data.DataApi.DataApi.getUserFollowsFromList方法的典型用法代码示例。如果您正苦于以下问题:Python DataApi.getUserFollowsFromList方法的具体用法?Python DataApi.getUserFollowsFromList怎么用?Python DataApi.getUserFollowsFromList使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类data.DataApi.DataApi
的用法示例。
在下文中一共展示了DataApi.getUserFollowsFromList方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: toDictionary
# 需要导入模块: from data.DataApi import DataApi [as 别名]
# 或者: from data.DataApi.DataApi import getUserFollowsFromList [as 别名]
def toDictionary(self, options=[], user=None):
'''To dictionary'''
# Remeber not to use 'user' because it is a parameter
idToUser = dict([(u.id(), u) for u in self.users()])
# If we need to, fetch Follows to check if there are return follows
# for if people in userIds follow the user passed in as a parameter
if user and UserList.Options.USER_FOLLOW in options:
userFollows = DataApi.getUserFollowsFromList(user.model(),
idToUser.keys())
userFollowIds = [f.userId for f in userFollows]
from Follow import Follow
idToFollow = dict([(f.userId, Follow(f)) for f in userFollows])
objList = []
for u in self.users():
obj = u.toDictionary()
if user and UserList.Options.USER_FOLLOW in options:
if u.id() in idToFollow:
follow = idToFollow[u.id()]
obj[User.Key.BLESSED] = follow.blessed(user)
obj[User.Key.FOLLOW] = True
else:
obj[User.Key.BLESSED] = False
obj[User.Key.FOLLOW] = False
objList.append(obj)
return objList
示例2: toDictionary
# 需要导入模块: from data.DataApi import DataApi [as 别名]
# 或者: from data.DataApi.DataApi import getUserFollowsFromList [as 别名]
def toDictionary(self, options=[], user=None):
'''To dictionary'''
from User import User
# get list of user ids we want to fetch
if FollowList.Options.FOLLOW_LIST in options:
userIds = [follow.userId() for follow in self.followList()]
elif FollowList.Options.FOLLOWER_LIST in options:
userIds = [follow.followerId() for follow in self.followList()]
else:
assert False, "Should have FOLLOW_LIST or FOLLOWER_LIST options"
users = User.getByUserIds(userIds)
# don't user 'user' because it is a parameter
idToUser = dict([(u.id(), u) for u in users])
# If we need to, fetch Follows to check if there are return follows
# for if people in userIds follow the user passed in as a parameter
if FollowList.Options.USER_FOLLOW in options:
userFollows = DataApi.getUserFollowsFromList(user.model(),
userIds)
userFollowIds = [f.userId for f in userFollows]
objList = []
for follow in self.followList():
if FollowList.Options.FOLLOW_LIST in options:
u = idToUser[follow.userId()]
elif FollowList.Options.FOLLOWER_LIST in options:
u = idToUser[follow.followerId()]
else:
assert False, "Should have FOLLOW_LIST or FOLLOWER_LIST options"
obj = u.toDictionary()
obj[User.Key.BLESSED] = follow.blessed(user)
if FollowList.Options.USER_FOLLOW in options:
obj[User.Key.FOLLOW] = u.id() in userFollowIds
objList.append(obj)
return objList