Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions sorl/thumbnail/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def write(self, content):
def delete(self):
return self.storage.delete(self.name)

def serialize_storage(self):
def serialize_storage(self, use_backend_name=False):
if isinstance(self.storage, LazyObject):
# if storage is wrapped in a lazy object we need to get the real
# thing.
Expand All @@ -192,6 +192,8 @@ def serialize_storage(self):
else:
cls = self.storage.__class__
backend = f"{cls.__module__}.{cls.__name__}"
if use_backend_name:
return backend
# Try our best to find and serialize the storage alias instead of the backend class.
for alias, params in storages.backends.items():
if params.get("BACKEND") == backend:
Expand All @@ -200,7 +202,7 @@ def serialize_storage(self):

@property
def key(self):
return tokey(self.name, self.serialize_storage())
return tokey(self.name, self.serialize_storage(use_backend_name=True))

def serialize(self):
return serialize_image_file(self)
Expand Down
2 changes: 1 addition & 1 deletion tests/thumbnail_tests/test_alternative_resolutions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def tearDown(self):
def test_retina(self):
get_thumbnail(self.image, '50x50')

cache_path = "test/cache/2c/0f/2c0f909d420e760b8dc4e1d1f79e705b"
cache_path = "test/cache/91/bb/91bb06cf9169e4c52132bb113f2d4c0d"
actions = [
f"exists: {cache_path}.jpg",

Expand Down
2 changes: 1 addition & 1 deletion tests/thumbnail_tests/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def setUp(self):
def test_nonascii(self):
# also test the get_thumbnail shortcut
th = get_thumbnail(self.name, '200x200')
self.assertEqual(th.url, '/media/test/cache/79/48/79489fd416471a8850d1c7c6f7a28343.jpg')
self.assertEqual(th.url, '/media/test/cache/f5/26/f52608b56718f62abc45a90ff9459f2c.jpg')

def tearDown(self):
shutil.rmtree(settings.MEDIA_ROOT)
19 changes: 19 additions & 0 deletions tests/thumbnail_tests/test_engines.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,25 @@ def test_storage_serialize(self):
'default',
)

self.assertEqual(
im.serialize_storage(use_backend_name=True),
'tests.thumbnail_tests.storage.TestStorage',
)
self.assertEqual(
ImageFile('http://www.image.jpg').serialize_storage(use_backend_name=True),
'sorl.thumbnail.images.UrlStorage',
)
self.assertEqual(
ImageFile('http://www.image.jpg', default.storage).serialize_storage(
use_backend_name=True
),
'tests.thumbnail_tests.storage.TestStorage',
)
self.assertEqual(
ImageFile('getit', default_storage).serialize_storage(use_backend_name=True),
'tests.thumbnail_tests.storage.TestStorage',
)

@unittest.skipIf(platform.system() == "Darwin", 'quality is saved a different way on os x')
def test_quality(self):
im = ImageFile(Item.objects.get(image='500x500.jpg').image)
Expand Down
4 changes: 2 additions & 2 deletions tests/thumbnail_tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def test_html_filter_local_url(self):

self.assertEqual(
'<img alt="A image!" '
'src="/media/test/cache/62/5b/625b3d4c6020c1179d7888ca8d29845d.jpg" />',
'src="/media/test/cache/c7/f2/c7f2880b48e9f07d46a05472c22f0fde.jpg" />',
val
)

Expand All @@ -38,6 +38,6 @@ def test_markdown_filter_local_url(self):
val = render_to_string('markdownfilter.html', {'text': text, }).strip()

self.assertEqual(
'![A image!](/media/test/cache/62/5b/625b3d4c6020c1179d7888ca8d29845d.jpg)',
'![A image!](/media/test/cache/c7/f2/c7f2880b48e9f07d46a05472c22f0fde.jpg)',
val
)
2 changes: 1 addition & 1 deletion tests/thumbnail_tests/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class StorageTestCase(BaseStorageTestCase):

def test_new(self):
get_thumbnail(self.image, '50x50')
cache_path = "test/cache/55/ce/55ceec8f0d3f20a89304da3a65644db0.jpg"
cache_path = "test/cache/45/bb/45bbbdab11e235a80e603aa119e8786b.jpg"
actions = [
f"exists: {cache_path}",
# open the original for thumbnailing
Expand Down
12 changes: 6 additions & 6 deletions tests/thumbnail_tests/test_templatetags.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def test_nested(self):
item = Item.objects.get(image='500x500.jpg')
val = render_to_string('thumbnail6.html', {'item': item, }).strip()
self.assertEqual(val, (
'<a href="/media/test/cache/bb/a2/bba263a67019189dfeb106ced24dcb4d.jpg">'
'<img src="/media/test/cache/a4/d3/a4d3b1e302148aed94200b3a05849884.jpg" '
'<a href="/media/test/cache/fc/f6/fcf65c09cc4bb8671147de41997422bf.jpg">'
'<img src="/media/test/cache/67/6b/676b2331a071478b0cb280d0edba7818.jpg" '
'width="400" height="400"></a>'
))

Expand Down Expand Up @@ -195,10 +195,10 @@ def test_nested(self):
self.assertEqual(
val,
(
'<a href="/media/test/cache/bb/a2/'
'bba263a67019189dfeb106ced24dcb4d.jpg">'
'<img src="/media/test/cache/a4/d3/'
'a4d3b1e302148aed94200b3a05849884.jpg" '
'<a href="/media/test/cache/fc/f6/'
'fcf65c09cc4bb8671147de41997422bf.jpg">'
'<img src="/media/test/cache/67/6b/'
'676b2331a071478b0cb280d0edba7818.jpg" '
'width="400" height="400"></a>'
)
)
Expand Down