当前位置: 首页>>代码示例>>Python>>正文


Python DataApi.getUserFollowsFromList方法代码示例

本文整理汇总了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
开发者ID:nikilster,项目名称:projectAwesome,代码行数:31,代码来源:UserList.py

示例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
开发者ID:nikilster,项目名称:projectAwesome,代码行数:41,代码来源:FollowList.py


注:本文中的data.DataApi.DataApi.getUserFollowsFromList方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。