Ejemplo n.º 1
0
 def i(self, short):
     try:
         image_id = short_url.decode_url(short)
     except ValueError:
         raise exception.ImageNotFound(reference=short)
     image = db_api.get_image_by_id(image_id=image_id)
     saved_path = path_join(conf.app.static_root,
                            image.relative_path.encode('UTF-8'))
     with file(saved_path) as fh:
         content = fh.read()
     override_template(None, content_type='image/png')
     return content
Ejemplo n.º 2
0
    def t(self, short):
        try:
            image_id = short_url.decode_url(short)
        except ValueError:
            raise exception.ImageNotFound(reference=short)

        image = db_api.get_image_by_id(image_id=image_id)
        relative_path = image.relative_path.encode('UTF-8')
        thumbnail_path = util.generate_thumbnail_path(relative_path)
        saved_path = path_join(conf.app.static_root, thumbnail_path)

        if not exists(saved_path):
            logger.debug('generating thumbnail on accessing: %s' % \
                         saved_path)
            util.save_thumbnail(saved_path)

        with file(saved_path) as fh:
            content = fh.read()

        override_template(None, content_type='image/jpeg')
        return content