mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-23 08:36:32 +00:00
Merge pull request #1627 from joachimesque/fix-preview-image-url
Don't change the preview image URL on update
This commit is contained in:
commit
ad6c860951
2 changed files with 11 additions and 9 deletions
|
@ -317,15 +317,21 @@ def save_and_cleanup(image, instance=None):
|
|||
"""Save and close the file"""
|
||||
if not isinstance(instance, (models.Book, models.User, models.SiteSettings)):
|
||||
return False
|
||||
uuid = uuid4()
|
||||
file_name = f"{instance.id}-{uuid}.jpg"
|
||||
image_buffer = BytesIO()
|
||||
|
||||
try:
|
||||
try:
|
||||
old_path = instance.preview_image.name
|
||||
file_name = instance.preview_image.name
|
||||
except ValueError:
|
||||
old_path = None
|
||||
file_name = None
|
||||
|
||||
if not file_name or file_name == "":
|
||||
uuid = uuid4()
|
||||
file_name = f"{instance.id}-{uuid}.jpg"
|
||||
|
||||
# Clean up old file before saving
|
||||
if file_name and default_storage.exists(file_name):
|
||||
default_storage.delete(file_name)
|
||||
|
||||
# Save
|
||||
image.save(image_buffer, format="jpeg", quality=75)
|
||||
|
@ -345,10 +351,6 @@ def save_and_cleanup(image, instance=None):
|
|||
else:
|
||||
instance.save(update_fields=["preview_image"])
|
||||
|
||||
# Clean up old file after saving
|
||||
if old_path and default_storage.exists(old_path):
|
||||
default_storage.delete(old_path)
|
||||
|
||||
finally:
|
||||
image_buffer.close()
|
||||
return True
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
celery==4.4.2
|
||||
colorthief==0.2.1
|
||||
Django==3.2.5
|
||||
django-imagekit==4.0.2
|
||||
django-imagekit==4.1.0
|
||||
django-model-utils==4.0.0
|
||||
environs==9.3.4
|
||||
flower==0.9.4
|
||||
|
|
Loading…
Reference in a new issue