Skip to content

Commit

Permalink
Adds a new setting to avoid checking if a thumbnail already exists be…
Browse files Browse the repository at this point in the history
…fore overwrite - #96 #351
  • Loading branch information
mariocesar committed Mar 20, 2015
1 parent 5568c79 commit eb569ad
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
9 changes: 9 additions & 0 deletions docs/reference/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -364,3 +364,12 @@ that regex replaces references to images with thumbnails.

This value sets the timeout value in seconds when retrieving a source image from a URL.
If no timeout value is specified, it will wait indefinitely for a response.

``THUMBNAIL_FORCE_OVERWRITE``
=========================

- Default: ``False``

Whenever we will check an existing thumbnail exists and avoid to overwrite or not.
Set this to true if you have an slow .exists() implementation on your storage backend of choice,
this will create the thumbnail without checking if it already exists.
3 changes: 2 additions & 1 deletion sorl/thumbnail/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ def get_thumbnail(self, file_, geometry_string, **options):

# We have to check exists() because the Storage backend does not
# overwrite in some implementations.
if not thumbnail.exists():

if not (settings.THUMBNAIL_FORCE_OVERWRITE and thumbnail.exists()):
try:
source_image = default.engine.get_image(source)
except IOError:
Expand Down
4 changes: 4 additions & 0 deletions sorl/thumbnail/conf/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,7 @@
# Should we flatten images by default (fixes a lot of transparency issues with
# imagemagick)
THUMBNAIL_FLATTEN = False

# Whenever we will check an existing thumbnail exists and avoid to overwrite or not.
# Set this to true if you have an slow .exists() implementation on your storage backend of choice.
THUMBNAIL_FORCE_OVERWRITE = False

0 comments on commit eb569ad

Please sign in to comment.