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


Python DataApi.DataApi类代码示例

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


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

示例1: toDictionary

    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,代码行数:57,代码来源:VisionCommentList.py

示例2: setInfo

 def setInfo(self, firstName, lastName, email, visionPrivacy):
     '''Returns True if something changed, else False'''
     change = False
     if Verifier.nameValid(firstName) and \
        Verifier.nameValid(lastName) and \
        Verifier.emailValid(email):
         change |= DataApi.setUserName(self.model(), firstName, lastName)
         change |= DataApi.setUserEmail(self.model(), email)
         change |= DataApi.setUserVisionPrivacy(self.model(), visionPrivacy)
     return change
开发者ID:nikilster,项目名称:projectAwesome,代码行数:10,代码来源:User.py

示例3: getById

    def getById(visionId, inquiringUser):
        '''Get vision by id with privileges of inquiringUser, else None.
       
        If inquiringUser==None, assume public is trying to access this vision.
        '''
        model = DataApi.getVision(visionId)
        if DataApi.NO_OBJECT_EXISTS == model:
            return None
        vision = Vision(model)

        # Ensure that user can access this vision
        relationship = Relationship.get(
                            inquiringUser.id() if inquiringUser else None,
                            vision.userId())
        ok = False
        if Relationship.NONE == relationship:
            # if no relationship, vision must be public
            if VisionPrivacy.PUBLIC == vision.privacy():
                ok = True
        elif Relationship.SELF == relationship:
            # if it is your own vision, you def have access
            ok = True

        if True == ok:
            return vision
        else:
            return None
开发者ID:nikilster,项目名称:projectAwesome,代码行数:27,代码来源:Vision.py

示例4: addVision

    def addVision(self, imageUrl, text, isUploaded, isPublic):
        '''Creates new vision
        
        TODO: What does isUploaded mean?
        
        Returns (Vision/None, None or error_msg if add vision failed)
        '''
        #TODO: Save page title and page URL?

        if imageUrl == "":
            return [None, "No image"]
        if len(text.strip()) <= 0:
            return [None, "No text"]

        pictureId, errorMsg = self._processAndUploadImageUrl(imageUrl, isUploaded)
        if pictureId == None:
            return [None, "Error saving picture"]

        privacy = VisionPrivacy.PUBLIC
        if not isPublic:
            privacy = VisionPrivacy.PRIVATE

        visionId = DataApi.addVision(self.model(), text, pictureId,
                                     0, 0, privacy)
        if visionId == DataApi.NO_OBJECT_EXISTS_ID:
            return [None, "Error creating vision"]
        vision = Vision.getById(visionId, self)
        if vision:
            return [vision, "Saved Vision!"]
        else:
            return [None, "Error retrieving vision"]
开发者ID:nikilster,项目名称:projectAwesome,代码行数:31,代码来源:User.py

示例5: toDictionary

    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,代码行数:29,代码来源:UserList.py

示例6: _processAndUploadImageUrl

    def _processAndUploadImageUrl(self, imageUrl, isUploaded):
        if imageUrl == "":
            return [None, "No image"]
        imageUpload = ImageUrlUpload(imageUrl)
        s3Vision = imageUpload.saveAsVisionImage(self.id())

        if None == s3Vision:
            return [None, "Invalid image"]
            
        pictureId = DataApi.addPicture(self.model(),
                                       imageUrl, isUploaded,
                                       s3Vision.s3Bucket(),
                                       s3Vision.origKey(),
                                       s3Vision.origWidth(),
                                       s3Vision.origHeight(),
                                       s3Vision.largeKey(),
                                       s3Vision.largeWidth(),
                                       s3Vision.largeHeight(),
                                       s3Vision.mediumKey(),
                                       s3Vision.mediumWidth(),
                                       s3Vision.mediumHeight(),
                                       s3Vision.smallKey(),
                                       s3Vision.smallWidth(),
                                       s3Vision.smallHeight())

        if pictureId == DataApi.NO_OBJECT_EXISTS_ID:
            return [None, "Error saving picture"]

        return [pictureId, "Success"]
开发者ID:nikilster,项目名称:projectAwesome,代码行数:29,代码来源:User.py

示例7: getFromVision

    def getFromVision(vision, maxComments):
        '''Get comment list from vision with max number, else None.

        NOTE: This assumes the user is vetted to access this vision.
        '''
        models  = DataApi.getVisionComments(vision.model(), maxComments)
        return VisionCommentList._getWithModels(models)
开发者ID:nikilster,项目名称:projectAwesome,代码行数:7,代码来源:VisionCommentList.py

示例8: getUserVisions

    def getUserVisions(user, targetUser):
        '''Gets vision of targetUser that are accessible by user.
        
        If user is None, it will treat it as public access.
        '''
        assert targetUser, "Invalid target user"
        userId = None
        if user:
            userId = user.id()
        models = DataApi.getVisionsForUser(targetUser.model())

        # determine relationship for filtering viewable visions
        relationship = Relationship.get(userId, targetUser.id())

        if Relationship.NONE == relationship:
            # If no relationship, only show public visions
            filtered = []
            for model in models:
                if model.privacy == VisionPrivacy.PUBLIC:
                    filtered.append(model)
            return VisionList(filtered)
        elif Relationship.SELF == relationship:
            # Show all visions
            return VisionList(models)
        else:
            assert False, "Invalid relationship value"
            return None
开发者ID:nikilster,项目名称:projectAwesome,代码行数:27,代码来源:VisionList.py

示例9: getById

 def getById(pictureId):
     '''Get picture by id, else None'''
     if pictureId > 0:
         model = DataApi.getPicture(pictureId)
         if DataApi.NO_OBJECT_EXISTS != model:
             return Picture(model)
     return None
开发者ID:nikilster,项目名称:projectAwesome,代码行数:7,代码来源:Picture.py

示例10: get

 def get(comment, user):
     '''Get VisionCommentLike or None'''
     if user == None:
         return None
     model = DataApi.getVisionCommentLike(comment.model(), user.model())
     if model == DataApi.NO_OBJECT_EXISTS:
         return None
     return VisionCommentLike(model)
开发者ID:nikilster,项目名称:projectAwesome,代码行数:8,代码来源:VisionCommentLike.py

示例11: getByIds

    def getByIds(visionIds, allowRemovedVisions=False):
        '''Note that this assumes we have access to all these visions.

        MUST do privacy checks before calling.
        '''
        models = DataApi.getVisionsById(visionIds,
                                        allowRemovedVisions=allowRemovedVisions)
        return VisionList(models)
开发者ID:nikilster,项目名称:projectAwesome,代码行数:8,代码来源:VisionList.py

示例12: followUser

    def followUser(self, user):
        '''Returns new follow, or None'''
        if self.id() == user.id():
            return None
        followModel = DataApi.addFollow(self.model(), user.model())

        if followModel:
            from ..WorkerJobs import Queue_followEmail
            Queue_followEmail(self.toDictionary(),
                              user.toDictionaryFull())
        return Follow(followModel)
开发者ID:nikilster,项目名称:projectAwesome,代码行数:11,代码来源:User.py

示例13: getRecentVisionActivity

    def getRecentVisionActivity(user):
        """Get list of visions we want to display from the recent activities"""

        # Get list of potential visions
        activities = DataApi.getRecentActivities()

        commentIds = set([a.objectId for a in activities if a.action == Activity.Action.COMMENT_ON_VISION])
        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)
        visionModels = DataApi.getVisionsById(visionIds, allowRemovedVisions=True)
        idToVision = dict([(v.id, v) for v in visionModels])

        # Now create ordered list without visions that have a duplicate
        # root vision, and without private visions
        rootIds = set()
        orderedVisions = []
        for a in activities:
            vision = None
            if a.action == Activity.Action.ADD_VISION:
                if a.objectId in idToVision:
                    vision = idToVision[a.objectId]
            elif a.action == Activity.Action.COMMENT_ON_VISION:
                if a.objectId in idToComment:
                    comment = idToComment[a.objectId]
                    if comment.visionId in idToVision:
                        vision = idToVision[comment.visionId]

            if (
                vision
                and vision.removed == False
                and vision.privacy == VisionPrivacy.PUBLIC
                and vision.rootId not in rootIds
            ):
                orderedVisions.append(vision)
                rootIds.add(vision.rootId)
        return VisionList(orderedVisions)
开发者ID:nikilster,项目名称:projectAwesome,代码行数:40,代码来源:Activity.py

示例14: edit

    def edit(self, text, isPublic):
        '''Set new text and/or privacy value
       
        Returns (True if change happened, error_msg if there is one)
        '''
        # Make sure text is valid
        text = text.strip()
        if len(text) < 0:
            return (False, "Text field is required.")

        # Make sure to maintain privacy! If already private, can't change to
        # public!
        if False == self.isPublic() and \
           True == isPublic and \
           DataApi.visionHasCommentsFromOthers(self.model(), self.userId()):
            return (False,
                    "Can't make vision public once there are comments from others.")
        # ok, now we can make the change
        privacy = VisionPrivacy.PRIVATE
        if isPublic:
            privacy = VisionPrivacy.PUBLIC
        return (DataApi.editVision(self.model(), text, privacy), "")
开发者ID:nikilster,项目名称:projectAwesome,代码行数:22,代码来源:Vision.py

示例15: setProfilePicture

    def setProfilePicture(self, file):
        '''Sets profile picture from file input stream

        Returns URL on success, else None
        '''
        image = ProfilePicture(file)
        url = None
        if file and image.isImage():
            url = image.uploadToS3(self.id())
            if url != None:
                if True == DataApi.setProfilePicture(self.model(), url):
                    return url
        return None
开发者ID:nikilster,项目名称:projectAwesome,代码行数:13,代码来源:User.py


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