2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-29 20:16:44 +00:00

Fix thumbnail command (#3243)

- New image size "preview" was not being generated
- Check was looking for existance of "thumbnail" (which did exist)
- Updated so that all image sizes are generated on a migration
This commit is contained in:
Oliver 2022-06-23 13:48:36 +10:00 committed by GitHub
parent 7283197bac
commit b247aa6062
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,9 +4,7 @@
""" """
import logging import logging
import os
from django.conf import settings
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from django.db.utils import OperationalError, ProgrammingError from django.db.utils import OperationalError, ProgrammingError
@ -27,18 +25,15 @@ class Command(BaseCommand):
return return
img = model.image img = model.image
url = img.thumbnail.name
loc = os.path.join(settings.MEDIA_ROOT, url)
if not os.path.exists(loc): logger.info(f"Generating thumbnail image for '{img}'")
logger.info(f"Generating thumbnail image for '{img}'")
try: try:
model.image.render_variations(replace=False) model.image.render_variations(replace=False)
except FileNotFoundError: except FileNotFoundError:
logger.warning(f"Warning: Image file '{img}' is missing") logger.warning(f"Warning: Image file '{img}' is missing")
except UnidentifiedImageError: except UnidentifiedImageError:
logger.warning(f"Warning: Image file '{img}' is not a valid image") logger.warning(f"Warning: Image file '{img}' is not a valid image")
def handle(self, *args, **kwargs): def handle(self, *args, **kwargs):
"""Rebuild all thumbnail images.""" """Rebuild all thumbnail images."""