本文整理汇总了Python中data.DataApi.DataApi.getVisionIdsLikedByUser方法的典型用法代码示例。如果您正苦于以下问题:Python DataApi.getVisionIdsLikedByUser方法的具体用法?Python DataApi.getVisionIdsLikedByUser怎么用?Python DataApi.getVisionIdsLikedByUser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类data.DataApi.DataApi
的用法示例。
在下文中一共展示了DataApi.getVisionIdsLikedByUser方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: toDictionary
# 需要导入模块: from data.DataApi import DataApi [as 别名]
# 或者: from data.DataApi.DataApi import getVisionIdsLikedByUser [as 别名]
def toDictionary(self, options=[], user=None):
'''For packaging to JSON output.
options input is list of Vision.Options when we want more information
fetched from DB and placed into objects
This batches up queries for pictures and comments across all the
visions. Whenever we want to get all this data across a list of
visions, it is good to use VisionList.toDictionary() instead of the
individual toDictionary() calls on objects.
'user' parameter is only used when LIKES in provided as
an option. If it is passed in, we also check whether this user likes
the visions or not.
'''
from User import User
retObj = []
# Start collecting picture ids
pictureIds = set()
if Vision.Options.PICTURE in options:
pictureIds = set([vision.pictureId() for vision in self.visions()])
# Get parent users if we need them
parentUserIds = set()
if Vision.Options.PARENT_USER in options:
parentVisionIds = set([vision.parentId()
for vision in self.visions()])
parentVisionIds.discard(0)
parentVisions = VisionList.getByIds(parentVisionIds,
allowRemovedVisions=True)
idToParentVisions = dict([(v.id(), v)
for v in parentVisions.visions()])
parentUserIds = set([parent.userId()
for parent in parentVisions.visions()])
# Get all users (including parent users if needed)
userIds = set([vision.userId() for vision in self.visions()])
users = User.getByUserIds(userIds.union(parentUserIds))
idToUser = dict([(u.id(), u) for u in users])
# If COMMENTS, get comments
if Vision.Options.COMMENTS in options:
commentList = VisionCommentList.getEmptyList()
for vision in self.visions():
# TODO: Speed up performance of this some time!
commentList.extend(vision.comments(5))
idToComments = {}
for comment in commentList.comments():
if not comment.visionId() in idToComments:
idToComments[comment.visionId()] = [comment]
else:
idToComments[comment.visionId()].append(comment)
if Vision.Options.COMMENT_PICTURES:
if comment.hasPicture():
pictureIds.add(comment.pictureId())
authorIds = set([comment.authorId()
for comment in commentList.comments()])
authors = User.getByUserIds(authorIds)
idToAuthor = dict([(author.id(), author) for author in authors])
# If COMMENT_LIKES
if Vision.Options.COMMENT_LIKES in options:
commentIds = [c.id() for c in commentList.comments()]
tuples = DataApi.getVisionCommentListLikeCount(commentIds)
idToCommentLikes = dict([(commentId, count)
for commentId, count in tuples])
if user:
commentUserLikes = DataApi.getVisionCommentIdsLikedByUser(
commentIds, user.id())
# If LIKES, get vision likes in batch
if Vision.Options.LIKES in options:
visionIds = [v.id() for v in self.visions()]
tuples = DataApi.getVisionListLikeCount(visionIds)
idToLikes = dict([(visionId, count) for visionId, count in tuples])
if user:
userLikes = DataApi.getVisionIdsLikedByUser(visionIds,
user.id())
# Get pictures and hash them
if (Vision.Options.PICTURE in options) or \
(Vision.Options.COMMENT_PICTURES in options):
pictureIds.discard(0)
pictures = Picture.getByIds(pictureIds)
idToPicture = dict([(picture.id(), picture)
for picture in pictures])
idToPicture[0] = ""
# Now start building object list to return
for vision in self.visions():
obj = vision.toDictionary()
if Vision.Options.USER in options:
obj[Vision.Key.USER] = idToUser[vision.userId()].toDictionary()
# If PICTURE
if Vision.Options.PICTURE in options:
#.........这里部分代码省略.........