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)
    def get(self, album_id):
        user = get_user()
        album = Album.get_by_id(
            int(album_id),
            DEFAULT_DOMAIN_KEY
        )

        if album:
            upload_url = blobstore.create_upload_url('/album/%s/upload-photo' % album_id)

            photo_query = Photo.query(
                ancestor=album.key
            )

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

            template_values = {
                'user': user,
                'album': album,
                'photos': photo_query.fetch(None),
                'comments': comments_query.fetch(None),
                'upload_url': upload_url,
            }

            self.render_template('view_album.html', template_values)
        else:
            self.raise_error(404)
    def get(self, album_id):
        album = Album.get_by_id(
            int(album_id),
            parent=DEFAULT_DOMAIN_KEY
        )

        if get_user().key == album.author:
            self.render_template('edit_album.html', {'album': album})
        else:
            self.raise_error(500)
    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))
    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)
    def get(self, album_id, comment_id):
        album = Album.get_by_id(
            int(album_id),
            parent=DEFAULT_DOMAIN_KEY
        )

        comment = Comment.query(
            Comment.parent == album.key
        ).fetch(None)

        if get_user().key == comment[0].author:
            comment[0].key.delete()

            self.redirect('/album/%s/view' % album_id)
        else:
            self.raise_error(500)
    def post(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
        )

        if photo.author == get_user().key:
            delete_photo(photo)

            self.redirect('/album/%s/view' % album_id)
        else:
            self.raise_error('500')
    def post(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
        )

        if photo.author == get_user().key:
            photo.name = self.request.get('photo_name')
            photo.put()

            self.redirect('/album/%s/photo/%s/view' % (album_id, photo_id))
        else:
            self.raise_error(500)
    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
        )

        if photo.author == get_user().key:
            template_values = {
                'album': album,
                'photo': photo,
            }

            self.render_template('edit_photo.html', template_values)
        else:
            self.raise_error(500)
Exemple #10
0
    def post(self, album_id):
        user = get_user()

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

            comment = Comment(parent=album.key)
            comment.text = self.request.get('comment_text')
            comment.author = user.key
            comment.parent = album.key

            comment.put()

            self.redirect('/album/%s/view' % album.key.integer_id())
        else:
            self.redirect_to_login()
Exemple #11
0
    def post(self, album_id):
        album = Album.get_by_id(
            int(album_id),
            parent=DEFAULT_DOMAIN_KEY
        )

        if album.author == get_user().key:
            photos_query = Photo.query(
                ancestor=album.key
            )

            photos = photos_query.fetch(None)
            for photo in photos:
                delete_photo(photo)

            album.key.delete()

            self.redirect('/')
        else:
            self.raise_error(500)
    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')
Exemple #13
0
    def get(self, album_id):
        user = get_user()

        if user:
            album = Album.get_by_id(
                int(album_id),
                parent=DEFAULT_DOMAIN_KEY
            )
            upload_url = blobstore.create_upload_url(
                '/album/%s/upload-photo' % album.key.integer_id()
            )

            template_values = {
                'user': user,
                'album': album,
                'upload_url': upload_url,
            }

            self.render_template('add_photo.html', template_values)
        else:
            self.redirect_to_login()