diff --git a/artel/artel/tasks.py b/artel/artel/tasks.py index 3a928a5..35b1ab0 100644 --- a/artel/artel/tasks.py +++ b/artel/artel/tasks.py @@ -15,17 +15,14 @@ THUMBNAIL_SIZES = { @shared_task -def generate_thumbnails(image_url): +def generate_thumbnails(image_path): try: + thumbnailer = get_thumbnailer(image_path) thumbnails = {} - thumbnailer = get_thumbnailer(image_url) - for size_name, (width, height, crop) in THUMBNAIL_SIZES.items(): 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 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 diff --git a/artel/docker-compose.yml b/artel/docker-compose.yml index 1d9b7cd..c4ac620 100644 --- a/artel/docker-compose.yml +++ b/artel/docker-compose.yml @@ -75,6 +75,7 @@ services: command: celery -A artel worker -l info volumes: - ./:/app + - media:/app/media env_file: - .env environment: diff --git a/artel/store/signals.py b/artel/store/signals.py index b630588..2124bc6 100644 --- a/artel/store/signals.py +++ b/artel/store/signals.py @@ -5,6 +5,6 @@ from artel.tasks import generate_thumbnails @receiver(post_save, sender=ProductTemplateImage) -def create_thumbnail_on_image_creation(sender, instance, created, **kwargs): - if created: - generate_thumbnails.delay(instance.image.url) +def generate_thumbnail(sender, instance, **kwargs): + image_path = instance.image.path + generate_thumbnails.delay(image_path)