Files: Get thumbnails from variations, rather than from 'link' property

The 'link' property might not exist, for example when a user is not a
Cloud subscriber.
This commit is contained in:
2016-05-10 12:45:27 +02:00
parent 1e44703147
commit a9920fa76a

View File

@@ -67,13 +67,22 @@ class File(List, Find, Create, Post, Update, Delete, Replace):
raise ValueError("Size should be in ({}), not {}"
.format(', '.join(THUMBNAIL_SIZES), size))
if self.variations:
thumbnail = next((item for item in self['variations']
if item['size'] == size), None)
if thumbnail:
return thumbnail['link']
if self.backend == 'gcs':
thumbnail_link = self.thumbnail_file(size, api=api)
return thumbnail_link
else:
if self.link:
root, ext = os.path.splitext(self.link)
return "{0}-{1}.jpg".format(root, size)
return None
def thumbnail_file(self, size, api=None):
"""Delivers a single thumbnail (child) file for an image. Before returning
we check that the parent is actually an image.