From f72cbd77f4f71e966ab83d7860c049acc476c18c Mon Sep 17 00:00:00 2001 From: Francesco Siddi Date: Fri, 11 Sep 2015 15:04:49 +0200 Subject: [PATCH] Added call to retrieve thumbnails for file nodes of type image --- pillarsdk/files.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pillarsdk/files.py b/pillarsdk/files.py index b09a017..b25dead 100755 --- a/pillarsdk/files.py +++ b/pillarsdk/files.py @@ -50,3 +50,23 @@ class File(List, Find, Create, Post, Update, Delete, Replace): if not files._items: return None return files + + def thumbnail(self, size, api=None): + """Delivers a single thumbnail (child) file for an image. Before returning + we check that the parent is actually an image. + :param path: the size (s, b, t, m, l, h) + """ + api = api or self.api + if size in ['s', 'b', 't', 'm', 'l', 'h']: + # We chack from the content_type if the file is an image + if self.content_type.split('/')[0] == 'image': + thumbnail = self.find_first({ + 'where': '{"parent" : "%s", "size" : "%s"}'\ + % (self._id, size), + }, api=api) + return thumbnail + else: + return None + else: + raise ValueError("Size should be (s, b, t, m, l, h)") +