當前位置: 首頁>>代碼示例>>Python>>正文


Python Photo.get_dict方法代碼示例

本文整理匯總了Python中photo.Photo.get_dict方法的典型用法代碼示例。如果您正苦於以下問題:Python Photo.get_dict方法的具體用法?Python Photo.get_dict怎麽用?Python Photo.get_dict使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在photo.Photo的用法示例。


在下文中一共展示了Photo.get_dict方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: load_by_likes

# 需要導入模塊: from photo import Photo [as 別名]
# 或者: from photo.Photo import get_dict [as 別名]
    def load_by_likes(self, photo_id, db, cursor):
        # select photos where like < likes_for(photo_id)
        # union
        # select photos where like = likes_for(photo_id) and timestamp < timestamp_for(photo_id)
        curr_photo = Photo()
        curr_photo.load_from_db(photo_id, cursor)
        curr_photo_likes = curr_photo.like_count(db, cursor)
        curr_photo_approve_timestamp = curr_photo.get_dict()["approved_at"]

        sql = "SELECT photos.id, photos.fb_id, photos.filename, photos.caption, \
           photos.owner_id, photos.state, photos.created_at, photos.approved_at, \
           likes_count.count \
           FROM photos \
           LEFT JOIN (SELECT photo_id, count(*) AS count FROM likes GROUP BY photo_id) AS likes_count \
           ON photos.id = likes_count.photo_id \
           WHERE likes_count.count = %s \
           AND photos.approved_at < %s \
           \
           UNION \
           \
           SELECT photos.id, photos.fb_id, photos.filename, photos.caption, \
           photos.owner_id, photos.state, photos.created_at, photos.approved_at, \
           likes_count.count \
           FROM photos \
           LEFT JOIN (SELECT photo_id, count(*) AS count FROM likes GROUP BY photo_id) AS likes_count \
           ON photos.id = likes_count.photo_id \
           WHERE likes_count.count < %s"

        try:
            cursor.execute(sql, (curr_photo_likes, curr_photo_approve_timestamp, curr_photo_likes))
            data = cursor.fetchall()

            for row in data:
                photo = Photo()
                photo.load_from_tuple(row)

                self.photos_list.append(photo)

            return self.photos_list
        except Exception, e:
            raise e
開發者ID:abhikandoi2000,項目名稱:snaps-web-app,代碼行數:43,代碼來源:photolist.py


注:本文中的photo.Photo.get_dict方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。