本文整理匯總了Python中catsnap.image_truck.ImageTruck.url_for_filename方法的典型用法代碼示例。如果您正苦於以下問題:Python ImageTruck.url_for_filename方法的具體用法?Python ImageTruck.url_for_filename怎麽用?Python ImageTruck.url_for_filename使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類catsnap.image_truck.ImageTruck
的用法示例。
在下文中一共展示了ImageTruck.url_for_filename方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_url_for_filename__with_extension
# 需要導入模塊: from catsnap.image_truck import ImageTruck [as 別名]
# 或者: from catsnap.image_truck.ImageTruck import url_for_filename [as 別名]
def test_url_for_filename__with_extension(self, _url, Config):
config = Mock()
config.bucket_name.return_value = 'greeble'
Config.return_value = config
ImageTruck.url_for_filename('CAFEBABE', extension=True)
_url.assert_called_once_with('CAFEBABE', 'greeble', extension=True)
示例2: show_image
# 需要導入模塊: from catsnap.image_truck import ImageTruck [as 別名]
# 或者: from catsnap.image_truck.ImageTruck import url_for_filename [as 別名]
def show_image(request_format, image_id, size):
session = Client().session()
image = session.query(Image).\
filter(Image.image_id == image_id).\
one()
if g.user:
albums = session.query(Album).all()
else:
albums = []
if image.album_id is not None:
album = session.query(Album).\
filter(Album.album_id == image.album_id).\
one()
else:
album = None
(prev, next) = image.neighbors()
resizes = session.query(ImageResize).\
filter(ImageResize.image_id == image_id).\
order_by(ImageResize.width.asc()).\
all()
url = ImageTruck.url_for_filename(image.filename)
if resizes and size in [r.suffix for r in resizes]:
url = '{0}_{1}'.format(url, size)
tags = image.get_tags()
if request_format == 'html':
return render_template('image.html.jinja',
image=image,
prev=prev,
next=next,
album=album,
albums=albums,
url=url,
tags=list(tags),
metadata_fields=filter(lambda (x,_): getattr(image, x), Image.metadata_fields),
getattr=getattr,
resizes=resizes,
size=size)
elif request_format == 'json':
return {
'description': image.description,
'title': image.title,
'camera': image.camera,
'photographed_at': image.photographed_at,
'focal_length': image.focal_length,
'aperture': image.aperture,
'shutter_speed': image.shutter_speed,
'iso': image.iso,
'album_id': image.album_id,
'tags': list(tags),
'source_url': url,
}
示例3: show_image
# 需要導入模塊: from catsnap.image_truck import ImageTruck [as 別名]
# 或者: from catsnap.image_truck.ImageTruck import url_for_filename [as 別名]
def show_image(request_format, image_id, size):
session = Client().session()
image = session.query(Image).filter(Image.image_id == image_id).one()
if g.user:
albums = session.query(Album).all()
else:
albums = []
if image.album_id is not None:
album = session.query(Album).filter(Album.album_id == image.album_id).one()
else:
album = None
(prev, next) = image.neighbors()
resizes = (
session.query(ImageResize).filter(ImageResize.image_id == image_id).order_by(ImageResize.width.asc()).all()
)
url = ImageTruck.url_for_filename(image.filename)
if resizes and size in [r.suffix for r in resizes]:
url = "{0}_{1}".format(url, size)
tags = image.get_tags()
if request_format == "html":
return render_template(
"image.html.jinja",
image=image,
prev=prev,
next=next,
album=album,
albums=albums,
url=url,
tags=list(tags),
metadata_fields=filter(lambda (x, _): getattr(image, x), Image.metadata_fields),
getattr=getattr,
resizes=resizes,
size=size,
)
elif request_format == "json":
return {
"description": image.description,
"title": image.title,
"camera": image.camera,
"photographed_at": image.photographed_at,
"focal_length": image.focal_length,
"aperture": image.aperture,
"shutter_speed": image.shutter_speed,
"iso": image.iso,
"album_id": image.album_id,
"tags": list(tags),
"source_url": url,
}
示例4: find
# 需要導入模塊: from catsnap.image_truck import ImageTruck [as 別名]
# 或者: from catsnap.image_truck.ImageTruck import url_for_filename [as 別名]
def find(request_format):
tag_names = request.args['tags'].strip().split(' ')
image_structs = []
image_data = Tag.get_image_data(tag_names)
for filename, image_id, caption in image_data:
image_structs.append({
'source_url': ImageTruck.url_for_filename(filename),
'url': url_for('show_image', image_id=image_id),
'caption': caption,
})
if request_format == 'html':
return render_template('find.html.jinja', images=image_structs)
elif request_format == 'json':
return image_structs
示例5: show_image
# 需要導入模塊: from catsnap.image_truck import ImageTruck [as 別名]
# 或者: from catsnap.image_truck.ImageTruck import url_for_filename [as 別名]
def show_image(request_format, image_id, size):
session = Client().session()
image = session.query(Image).\
filter(Image.image_id == image_id).\
one()
if g.user:
albums = session.query(Album).all()
else:
albums = []
try:
album = filter(lambda a: a.album_id == image.album_id, albums)[0]
except IndexError:
album = None
resizes = session.query(ImageResize).\
filter(ImageResize.image_id == image_id).\
order_by(ImageResize.width.asc()).\
all()
url = ImageTruck.url_for_filename(image.filename)
if resizes and size != 'original':
if size not in map(lambda r: r.suffix, resizes):
size = resizes[0].suffix
url = '%s_%s' % (url, size)
tags = image.get_tags()
if request_format == 'html':
return render_template('image.html.jinja',
image=image,
album=album,
albums=albums,
url=url,
tags=tags,
resizes=resizes,
user=g.user,
size=size)
elif request_format == 'json':
return {
'description': image.description,
'title': image.title,
'camera': image.camera,
'photographed_at': image.photographed_at,
'focal_length': image.focal_length,
'aperture': image.aperture,
'shutter_speed': image.shutter_speed,
'iso': image.iso,
'album_id': image.album_id,
'tags': list(tags),
'source_url': url,
}
示例6: test_url_for_filename
# 需要導入模塊: from catsnap.image_truck import ImageTruck [as 別名]
# 或者: from catsnap.image_truck.ImageTruck import url_for_filename [as 別名]
def test_url_for_filename(self):
eq_(ImageTruck.url_for_filename('CAFEBABE'),
'https://s3.amazonaws.com/greeble/CAFEBABE')
示例7: test_url_for_filename
# 需要導入模塊: from catsnap.image_truck import ImageTruck [as 別名]
# 或者: from catsnap.image_truck.ImageTruck import url_for_filename [as 別名]
def test_url_for_filename(self, Config):
config = Mock()
config.bucket_name.return_value = 'greeble'
Config.return_value = config
eq_(ImageTruck.url_for_filename('CAFEBABE'),
'https://s3.amazonaws.com/greeble/CAFEBABE')