コード例 #1
0
 def toDictionary(self, options=[], user=None):
     '''For packaging in JSON objects.
     
     Pass in list of VisionComment.Options.* to include other info in objs
     '''
     obj = {  VisionComment.Key.ID : self.id(),
              VisionComment.Key.VISION_ID : self.visionId(),
              VisionComment.Key.AUTHOR_ID : self.authorId(),
              VisionComment.Key.TEXT : self.text(),
              VisionComment.Key.CREATED: self.created().isoformat(),
           }
     if VisionComment.Options.AUTHOR in options:
         from User import User
         obj = self.toDictionary()
         author = User.getById(self.authorId())
         if author:
             obj[VisionComment.Key.AUTHOR] = author.toDictionary()
     if VisionComment.Options.LIKES in options:
         obj[VisionComment.Key.LIKE] = { 
                             VisionComment.Key.LIKE_COUNT: self.likeCount() }
         if user:
             obj[VisionComment.Key.LIKE][VisionComment.Key.USER_LIKE] = \
                                                         self.likedBy(user)
     if VisionComment.Options.PICTURE in options:
         if self.hasPicture():
             from Picture import Picture
             picture = Picture.getById(self.pictureId())
             if picture:
                 obj[VisionComment.Key.PICTURE] = picture.toDictionary()
     return obj
コード例 #2
0
ファイル: Vision.py プロジェクト: nikilster/projectAwesome
 def picture(self):
     '''Returns Picture object for this Vision, or None'''
     return Picture.getById(self.pictureId())