Fixed thumbnail generation
rodzic
4d8198edbf
commit
b8fe41f551
|
@ -15,17 +15,14 @@ THUMBNAIL_SIZES = {
|
||||||
|
|
||||||
|
|
||||||
@shared_task
|
@shared_task
|
||||||
def generate_thumbnails(image_url):
|
def generate_thumbnails(image_path):
|
||||||
try:
|
try:
|
||||||
|
thumbnailer = get_thumbnailer(image_path)
|
||||||
thumbnails = {}
|
thumbnails = {}
|
||||||
thumbnailer = get_thumbnailer(image_url)
|
|
||||||
|
|
||||||
for size_name, (width, height, crop) in THUMBNAIL_SIZES.items():
|
for size_name, (width, height, crop) in THUMBNAIL_SIZES.items():
|
||||||
thumbnail = thumbnailer.get_thumbnail({'size': (width, height), 'crop': crop})
|
thumbnail = thumbnailer.get_thumbnail({'size': (width, height), 'crop': crop})
|
||||||
thumbnail_url = thumbnail.url
|
thumbnails[size_name] = thumbnail.url
|
||||||
thumbnails[size_name] = thumbnail_url
|
|
||||||
|
|
||||||
return thumbnails
|
return thumbnails
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.exception(f"Error generating thumbnails for image_instance {image_url}: {e}")
|
logger.exception(f"Error generating thumbnails for image_instance {image_path}: {e}")
|
||||||
return None
|
return None
|
||||||
|
|
|
@ -75,6 +75,7 @@ services:
|
||||||
command: celery -A artel worker -l info
|
command: celery -A artel worker -l info
|
||||||
volumes:
|
volumes:
|
||||||
- ./:/app
|
- ./:/app
|
||||||
|
- media:/app/media
|
||||||
env_file:
|
env_file:
|
||||||
- .env
|
- .env
|
||||||
environment:
|
environment:
|
||||||
|
|
|
@ -5,6 +5,6 @@ from artel.tasks import generate_thumbnails
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_save, sender=ProductTemplateImage)
|
@receiver(post_save, sender=ProductTemplateImage)
|
||||||
def create_thumbnail_on_image_creation(sender, instance, created, **kwargs):
|
def generate_thumbnail(sender, instance, **kwargs):
|
||||||
if created:
|
image_path = instance.image.path
|
||||||
generate_thumbnails.delay(instance.image.url)
|
generate_thumbnails.delay(image_path)
|
||||||
|
|
Ładowanie…
Reference in New Issue