website/hub/services/management/commands/update_image_properties.py

40 lines
1.3 KiB
Python

from django.core.management.base import BaseCommand
from hub.services.models.images import ImageLibrary
class Command(BaseCommand):
help = "Update image properties for existing images in the library"
def handle(self, *args, **options):
"""
Update image properties for all images in the library.
This is especially useful after adding SVG support.
"""
images = ImageLibrary.objects.all()
updated_count = 0
error_count = 0
self.stdout.write(f"Updating properties for {images.count()} images...")
for image in images:
try:
# Force update of image properties
image._update_image_properties()
updated_count += 1
# Show progress
if updated_count % 10 == 0:
self.stdout.write(f"Updated {updated_count} images...")
except Exception as e:
error_count += 1
self.stdout.write(
self.style.ERROR(f"Error updating {image.name}: {str(e)}")
)
self.stdout.write(
self.style.SUCCESS(
f"Successfully updated {updated_count} images. "
f"Errors: {error_count}"
)
)