Check If Sorl Thumbnail Has Already Cached An Image Using The Low Level Api
Sorl thumbnail has a low-level API that allows you to do, for example: from sorl.thumbnail import get_thumbnail im = get_thumbnail(my_file, '100x100', crop='center', quality=99) T
Solution 1:
In my version sorl.thumbnail
, 11.12
, the method get_thumbnail
is defined in sorl.thumbnail.base.py and starts as follows:
defget_thumbnail(self, file_, geometry_string, **options):
"""..."""
source = ImageFile(file_)
for key, value in self.default_options.iteritems():
options.setdefault(key, value)
# ...for key, attr in self.extra_options:
value = getattr(settings, attr)
if value != getattr(default_settings, attr):
options.setdefault(key, value)
name = self._get_thumbnail_filename(source, geometry_string, options)
thumbnail = ImageFile(name, default.storage)
cached = default.kvstore.get(thumbnail)
if cached:
return cached
ifnot thumbnail.exists():
...
If you use this code and return something like
cached or thumbnail.exists()
this should give you the desired result.
Post a Comment for "Check If Sorl Thumbnail Has Already Cached An Image Using The Low Level Api"