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


Python Album.get_by_id方法代碼示例

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


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

示例1: get

# 需要導入模塊: from models import Album [as 別名]
# 或者: from models.Album import get_by_id [as 別名]
    def get(self, album_id, photo_id):
        album = Album.get_by_id(
            int(album_id),
            parent=DEFAULT_DOMAIN_KEY
        )
        photo = Photo.get_by_id(
            int(photo_id),
            parent=album.key
        )

        image_url = '%s/album/%s/photo/%s' % (
            self.request.host_url,
            album.key.integer_id(),
            photo.key.integer_id()
        )

        comments_query = Comment.query(
            Comment.parent == photo.key
        ).order(-Comment.date_created)

        comments = comments_query.fetch(None)

        template_values = {
            'image_url': image_url,
            'photo': photo,
            'album': album,
            'comments': comments,
        }

        self.render_template('view_photo.html', template_values)
開發者ID:MichaelAquilina,項目名稱:Photo-Nebula,代碼行數:32,代碼來源:views.py

示例2: get

# 需要導入模塊: from models import Album [as 別名]
# 或者: from models.Album import get_by_id [as 別名]
    def get(self, album_id, photo_id):
        album = Album.get_by_id(
            int(album_id),
            parent=DEFAULT_DOMAIN_KEY
        )
        photo = Photo.get_by_id(
            int(photo_id),
            parent=album.key
        )

        # All possible options
        height = self.request.get('height')
        width = self.request.get('width')
        rotate = self.request.get('rotate')
        lucky = self.request.get('lucky')
        hflip = self.request.get('hflip')

        if height or width or rotate or hflip:
            try:
                img = images.Image(blob_key=photo.blob_info_key)

                height = None if not height else int(height)
                width = None if not width else int(width)
                rotate = None if not rotate else int(rotate)
                lucky = None if not lucky else bool(lucky)
                hflip = None if not hflip else bool(hflip)

                if width and height:
                    # Resizing always preserves aspect ratio
                    img.resize(height=height, width=width)
                elif width:
                    img.resize(width=width)
                elif height:
                    img.resize(height=height)

                if rotate:
                    img.rotate(rotate)

                if hflip:
                    img.horizontal_flip()

                if lucky:
                    img.im_feeling_lucky()

                img = img.execute_transforms(output_encoding=images.PNG)

                self.response.headers['Content-Type'] = 'image/png'
                self.response.write(img)
            except Exception as e:
                self.response.write('Unable to process request: %s' % e.message)
        else:
            self.send_blob(blobstore.BlobInfo.get(photo.blob_info_key))
開發者ID:MichaelAquilina,項目名稱:Photo-Nebula,代碼行數:54,代碼來源:photos.py

示例3: post

# 需要導入模塊: from models import Album [as 別名]
# 或者: from models.Album import get_by_id [as 別名]
    def post(self, album_id):
        album = Album.get_by_id(
            int(album_id),
            parent=DEFAULT_DOMAIN_KEY
        )

        if get_user().key == album.author:
            album.name = self.request.get('album_name')
            album.description = self.request.get('album_desc')
            album.put()

            self.redirect('/album/%s/view' % album_id)
        else:
            self.raise_error(500)
開發者ID:MichaelAquilina,項目名稱:Photo-Nebula,代碼行數:16,代碼來源:views.py

示例4: post

# 需要導入模塊: from models import Album [as 別名]
# 或者: from models.Album import get_by_id [as 別名]
    def post(self, album_id):
        uploaded_files = self.get_uploads('photo')

        user = get_user()

        if user:
            album = Album.get_by_id(
                int(album_id),
                parent=DEFAULT_DOMAIN_KEY
            )

            photo = Photo(parent=album.key)
            photo.author = user.key
            photo.name = self.request.get('photo_name')
            photo.blob_info_key = uploaded_files[0].key()

            photo.put()

            self.redirect('/album/%s/view' % album.key.integer_id())
        else:
            self.response.write('You must be signed in with your google account to upload photos')
開發者ID:MichaelAquilina,項目名稱:Photo-Nebula,代碼行數:23,代碼來源:photos.py


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