mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-18 21:15:41 +00:00
Move "rebuild_thumbnails" to being a management command
- Does not run every time the server reboots - Has to be called manually - Normally does not need to be run and is a long-running process!
This commit is contained in:
@ -24,40 +24,8 @@ class PartConfig(AppConfig):
|
||||
"""
|
||||
|
||||
if canAppAccessDatabase():
|
||||
self.generate_part_thumbnails()
|
||||
self.update_trackable_status()
|
||||
|
||||
def generate_part_thumbnails(self):
|
||||
"""
|
||||
Generate thumbnail images for any Part that does not have one.
|
||||
This function exists mainly for legacy support,
|
||||
as any *new* image uploaded will have a thumbnail generated automatically.
|
||||
"""
|
||||
|
||||
from .models import Part
|
||||
|
||||
logger.debug("InvenTree: Checking Part image thumbnails")
|
||||
|
||||
try:
|
||||
# Only check parts which have images
|
||||
for part in Part.objects.exclude(image=None):
|
||||
if part.image:
|
||||
url = part.image.thumbnail.name
|
||||
loc = os.path.join(settings.MEDIA_ROOT, url)
|
||||
|
||||
if not os.path.exists(loc):
|
||||
logger.info("InvenTree: Generating thumbnail for Part '{p}'".format(p=part.name))
|
||||
try:
|
||||
part.image.render_variations(replace=False)
|
||||
except FileNotFoundError:
|
||||
logger.warning(f"Image file '{part.image}' missing")
|
||||
pass
|
||||
except UnidentifiedImageError:
|
||||
logger.warning(f"Image file '{part.image}' is invalid")
|
||||
except (OperationalError, ProgrammingError):
|
||||
# Exception if the database has not been migrated yet
|
||||
pass
|
||||
|
||||
def update_trackable_status(self):
|
||||
"""
|
||||
Check for any instances where a trackable part is used in the BOM
|
||||
|
Reference in New Issue
Block a user