Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0][FIX] storage_thumbnail: always use slugified url_key #383

Merged
merged 1 commit into from
Jul 10, 2024
Merged
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
1 change: 1 addition & 0 deletions storage_thumbnail/models/thumbnail_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def get_existing_thumbnail(self, size_x, size_y, url_key=None):
return thumbnail

def get_or_create_thumbnail(self, size_x, size_y, url_key=None):
url_key = self._get_url_key(url_key)
thumbnail = self.get_existing_thumbnail(size_x, size_y, url_key=url_key)
if not thumbnail and self.data:
vals = self.env["storage.thumbnail"]._prepare_thumbnail(
Expand Down
12 changes: 12 additions & 0 deletions storage_thumbnail/tests/test_thumbnail.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ def test_thumbnail(self):
thumb.unlink()
self.assertTrue(file_id.to_delete)

def test_image_get_or_create_thumbnail_no_duplicate(self):
# Ensure no duplicate is generated thanks to unique url_key
image = self._create_image()
self.assertTrue(image.url)
self.assertEqual(len(image.thumbnail_ids), 2)
thumb = image.thumb_small_id
thumb.url_key = "test"
existing_thumb = image.get_or_create_thumbnail(
thumb.size_x, thumb.size_y, url_key="TEST"
)
self.assertEqual(thumb, existing_thumb)

def test_model(self):
image = self._create_image()
self.assertTrue(image.url)
Expand Down
Loading