From a9920fa76a436a301294b07fe7f54fed81fc464e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Tue, 10 May 2016 12:45:27 +0200 Subject: [PATCH] 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. --- pillarsdk/files.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pillarsdk/files.py b/pillarsdk/files.py index 93beb36..df9a15d 100755 --- a/pillarsdk/files.py +++ b/pillarsdk/files.py @@ -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.