Skip to content

Commit

Permalink
add possibility to use custom storage via get_thumbnail()
Browse files Browse the repository at this point in the history
  • Loading branch information
marcinn committed Oct 9, 2016
1 parent e25f863 commit 61557b4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 2 additions & 0 deletions docs/examples.rst
Expand Up @@ -180,3 +180,5 @@ Store::

delete(my_file)



6 changes: 4 additions & 2 deletions sorl/thumbnail/base.py
Expand Up @@ -74,8 +74,10 @@ def get_thumbnail(self, file_, geometry_string, **options):
"""
logger.debug('Getting thumbnail for file [%s] at [%s]', file_, geometry_string)

storage = options.pop('storage', default.storage)

if file_:
source = ImageFile(file_)
source = ImageFile(file_, storage=storage)
elif settings.THUMBNAIL_DUMMY:
return DummyImageFile(geometry_string)
else:
Expand All @@ -97,7 +99,7 @@ def get_thumbnail(self, file_, geometry_string, **options):
options.setdefault(key, value)

name = self._get_thumbnail_filename(source, geometry_string, options)
thumbnail = ImageFile(name, default.storage)
thumbnail = ImageFile(name, storage)
cached = default.kvstore.get(thumbnail)

if cached:
Expand Down
5 changes: 4 additions & 1 deletion sorl/thumbnail/templatetags/thumbnail.py
Expand Up @@ -123,6 +123,9 @@ def __init__(self, parser, token):
self.nodelist_empty = parser.parse(('endthumbnail',))
parser.delete_first_token()

def _get_thumbnail(self, file_, geometry, **options):
return get_thumbnail(file_, geometry, **options)

def _render(self, context):
file_ = self.file_.resolve(context)
geometry = self.geometry.resolve(context)
Expand All @@ -135,7 +138,7 @@ def _render(self, context):
else:
options[key] = value

thumbnail = get_thumbnail(file_, geometry, **options)
thumbnail = self._get_thumbnail(file_, geometry, **options)

if not thumbnail or (isinstance(thumbnail, DummyImageFile) and self.nodelist_empty):
if self.nodelist_empty:
Expand Down

0 comments on commit 61557b4

Please sign in to comment.