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


Python DataApi.getUsersFromIds方法代码示例

本文整理汇总了Python中data.DataApi.DataApi.getUsersFromIds方法的典型用法代码示例。如果您正苦于以下问题:Python DataApi.getUsersFromIds方法的具体用法?Python DataApi.getUsersFromIds怎么用?Python DataApi.getUsersFromIds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在data.DataApi.DataApi的用法示例。


在下文中一共展示了DataApi.getUsersFromIds方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: toDictionary

# 需要导入模块: from data.DataApi import DataApi [as 别名]
# 或者: from data.DataApi.DataApi import getUsersFromIds [as 别名]
    def toDictionary(self, options=[], user=None):
        '''For packaging JSON objects
        
        Pass in list of VisionComment.Options.* for extra information
        '''
        objs = []
        commentList = self._commentModels

        if self.length() > 0:
            from Picture import Picture
            idToPicture = dict()
            if VisionComment.Options.PICTURE in options:
                pictureIds = set([c.pictureId() for c in self.comments()])
                pictureIds.discard(0)
                pictures = Picture.getByIds(pictureIds)
                idToPicture = dict([(picture.id(), picture)
                                   for picture in pictures])

            if VisionComment.Options.AUTHOR in options:
                authorIds = set([comment.authorId()
                                                for comment in self.comments()])
                authors = DataApi.getUsersFromIds(authorIds)
                idToAuthor = dict([(u.id, u) for u in authors])

            # If LIKES
            if VisionComment.Options.LIKES in options:
                commentIds = [c.id() for c in self.comments()]
                tuples = DataApi.getVisionCommentListLikeCount(commentIds)
                idToLikeCount = dict([(commentId, count)
                                       for commentId, count in tuples])
                if user:
                    commentUserLikes = DataApi.getVisionCommentIdsLikedByUser(
                                                        commentIds, user.id())

            for comment in commentList:
                obj = VisionComment(comment).toDictionary()
                if VisionComment.Options.AUTHOR in options:
                    from User import User
                    author = idToAuthor[comment.authorId]
                    obj[VisionComment.Key.AUTHOR] = User(author).toDictionary()
                    # If LIKES
                    if VisionComment.Options.LIKES in options:
                        obj[VisionComment.Key.LIKE] = \
                                    { VisionComment.Key.LIKE_COUNT :
                                      idToLikeCount[comment.id] if
                                      comment.id in idToLikeCount else 0 }
                        if user:
                            obj[VisionComment.Key.LIKE]\
                               [VisionComment.Key.USER_LIKE] =\
                                                comment.id in commentUserLikes
                if VisionComment.Options.PICTURE in options:
                    if comment.pictureId > 0 and \
                       comment.pictureId in idToPicture:
                        cp = idToPicture[comment.pictureId]
                        obj[VisionComment.Key.PICTURE] = cp.toDictionary()
                objs.append(obj)
        return objs
开发者ID:nikilster,项目名称:projectAwesome,代码行数:59,代码来源:VisionCommentList.py

示例2: getByUserIds

# 需要导入模块: from data.DataApi import DataApi [as 别名]
# 或者: from data.DataApi.DataApi import getUsersFromIds [as 别名]
 def getByUserIds(userIds):
     '''Gets a list of Users from a list of userIds'''
     models = DataApi.getUsersFromIds(userIds)
     return [User(model) for model in models]
开发者ID:nikilster,项目名称:projectAwesome,代码行数:6,代码来源:User.py

示例3: getByUserIds

# 需要导入模块: from data.DataApi import DataApi [as 别名]
# 或者: from data.DataApi.DataApi import getUsersFromIds [as 别名]
 def getByUserIds(userIds):
     models = DataApi.getUsersFromIds(userIds)
     return UserList(models)
开发者ID:nikilster,项目名称:projectAwesome,代码行数:5,代码来源:UserList.py

示例4: getUserFeed

# 需要导入模块: from data.DataApi import DataApi [as 别名]
# 或者: from data.DataApi.DataApi import getUsersFromIds [as 别名]
    def getUserFeed(user):
        # Get set of all userIds to fetch activities from
        # This includes following ids, and own userId
        follows = user.getFollows()
        userIds = set()
        for f in follows.followList():
            userIds.add(f.userId())
        userIds.add(user.id())

        # Fetch activities
        activities = DataApi.getActivities(userIds)

        # Fetch all objects and create dictonary objects now. Might as well
        # here for now since we don't need anything else yet.
        # TODO: probably will need to change later

        followIds = set([a.objectId for a in activities if a.action == Activity.Action.FOLLOW])
        commentLikeIds = set([a.objectId for a in activities if a.action == Activity.Action.LIKE_VISION_COMMENT])
        visionLikeIds = set([a.objectId for a in activities if a.action == Activity.Action.LIKE_VISION])
        followModels = DataApi.getFollowsById(followIds)
        commentLikeModels = DataApi.getVisionCommentLikesById(commentLikeIds)
        visionLikeModels = DataApi.getVisionLikesById(visionLikeIds)

        idToFollow = dict([(f.id, f) for f in followModels])
        idToCommentLike = dict([(l.id, l) for l in commentLikeModels])
        idToVisionLike = dict([(l.id, l) for l in visionLikeModels])

        commentIds = set([a.objectId for a in activities if a.action == Activity.Action.COMMENT_ON_VISION])
        for l in commentLikeModels:
            commentIds.add(l.visionCommentId)
        commentModels = DataApi.getVisionCommentsById(commentIds)
        idToComment = dict([(c.id, c) for c in commentModels])

        visionIds = set([a.objectId for a in activities if a.action == Activity.Action.ADD_VISION])
        for c in commentModels:
            visionIds.add(c.visionId)
        for l in visionLikeModels:
            visionIds.add(l.visionId)
        unfilteredVisionsModels = DataApi.getVisionsById(visionIds, allowRemovedVisions=True)

        userIds = set([a.subjectId for a in activities if a.action == Activity.Action.JOIN_SITE])
        for c in commentModels:
            userIds.add(c.authorId)
        for l in visionLikeModels:
            userIds.add(l.userId)
        for l in commentLikeModels:
            userIds.add(l.userId)
        for f in followModels:
            userIds.add(f.followerId)
            userIds.add(f.userId)
        userModels = DataApi.getUsersFromIds(userIds)
        idToUser = dict([(u.id, u) for u in userModels])

        # At this point we have all the visions models for the activities
        # We need to remove the visions that we shouldn't allow this user to
        # see
        filteredVisionModels = []
        for vision in unfilteredVisionsModels:
            # vision should not be removed, and be either public, or a
            # private vision you own
            if vision.removed == False and (vision.privacy == VisionPrivacy.PUBLIC or vision.userId == user.id()):
                filteredVisionModels.append(vision)
        visionList = VisionList(filteredVisionModels)

        # Now we have a list of all
        visionObjs = visionList.toDictionary(
            options=[
                Vision.Options.PICTURE,
                Vision.Options.USER,
                Vision.Options.PARENT_USER,
                Vision.Options.COMMENTS,
                Vision.Options.COMMENT_PICTURES,
                Vision.Options.LIKES,
                Vision.Options.COMMENT_LIKES,
            ],
            user=user,
        )
        idToVisionObj = dict([(v[Vision.Key.ID], v) for v in visionObjs])

        # Now build activities!
        feedObjList = []
        visionIdToFeedObj = dict()
        for activity in activities:
            # JOIN SITE
            if activity.action == Activity.Action.JOIN_SITE:
                # Already have enough info to render this activity
                newUser = User(idToUser[activity.subjectId])

                obj = dict()
                obj[Activity.Key.TYPE] = Activity.FeedItem.JOIN
                obj[Activity.Key.USER] = newUser.toDictionary()
                obj[Activity.Key.CREATED] = activity.created.isoformat()

                feedObjList.append(obj)
            # FOLLOW
            elif activity.action == Activity.Action.FOLLOW:
                follow = idToFollow[activity.objectId]
                follower = User(idToUser[follow.followerId])
                following = User(idToUser[follow.userId])

#.........这里部分代码省略.........
开发者ID:nikilster,项目名称:projectAwesome,代码行数:103,代码来源:Activity.py


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