add support for svg images in library 2
This commit is contained in:
parent
ff3a09d30c
commit
a2489a7651
3 changed files with 240 additions and 0 deletions
40
hub/services/management/commands/update_image_properties.py
Normal file
40
hub/services/management/commands/update_image_properties.py
Normal file
|
@ -0,0 +1,40 @@
|
|||
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}"
|
||||
)
|
||||
)
|
24
hub/services/migrations/0044_add_svg_support.py
Normal file
24
hub/services/migrations/0044_add_svg_support.py
Normal file
|
@ -0,0 +1,24 @@
|
|||
# Generated by Django 5.2 on 2025-07-08 10:51
|
||||
|
||||
import hub.services.models.base
|
||||
import hub.services.models.images
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("services", "0043_remove_article_image_remove_cloudprovider_logo_and_more"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="imagelibrary",
|
||||
name="image",
|
||||
field=models.FileField(
|
||||
help_text="Upload image file (max 1MB) - supports JPEG, PNG, GIF, WebP, BMP, TIFF, and SVG",
|
||||
upload_to=hub.services.models.images.get_image_upload_path,
|
||||
validators=[hub.services.models.base.validate_image_or_svg],
|
||||
),
|
||||
),
|
||||
]
|
Loading…
Add table
Add a link
Reference in a new issue