2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-04 12:40:57 +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:
Oliver
2021-10-05 08:05:26 +11:00
parent 17df4ca91e
commit 0c04bfaa85
4 changed files with 83 additions and 63 deletions

View File

@ -23,29 +23,4 @@ class CompanyConfig(AppConfig):
This function is called whenever the Company app is loaded.
"""
if canAppAccessDatabase():
self.generate_company_thumbs()
def generate_company_thumbs(self):
from .models import Company
logger.debug("Checking Company image thumbnails")
try:
for company in Company.objects.all():
if company.image:
url = company.image.thumbnail.name
loc = os.path.join(settings.MEDIA_ROOT, url)
if not os.path.exists(loc):
logger.info("InvenTree: Generating thumbnail for Company '{c}'".format(c=company.name))
try:
company.image.render_variations(replace=False)
except FileNotFoundError:
logger.warning(f"Image file '{company.image}' missing")
except UnidentifiedImageError:
logger.warning(f"Image file '{company.image}' is invalid")
except (OperationalError, ProgrammingError):
# Getting here probably meant the database was in test mode
pass
pass