mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Check for missing part thumbnails when the server first runs
This commit is contained in:
parent
97f605ef55
commit
7fb89e4dbe
@ -1,7 +1,36 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
from django.db.utils import OperationalError, ProgrammingError
|
||||||
from django.apps import AppConfig
|
from django.apps import AppConfig
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
|
|
||||||
class PartConfig(AppConfig):
|
class PartConfig(AppConfig):
|
||||||
name = 'part'
|
name = 'part'
|
||||||
|
|
||||||
|
def ready(self):
|
||||||
|
"""
|
||||||
|
This function is called whenever the Part app is loaded.
|
||||||
|
"""
|
||||||
|
|
||||||
|
self.generate_part_thumbnails()
|
||||||
|
|
||||||
|
def generate_part_thumbnails(self):
|
||||||
|
from .models import Part
|
||||||
|
|
||||||
|
print("Checking Part image thumbnails")
|
||||||
|
|
||||||
|
try:
|
||||||
|
for part in Part.objects.all():
|
||||||
|
if part.image:
|
||||||
|
url = part.image.thumbnail.name
|
||||||
|
#if url.startswith('/'):
|
||||||
|
# url = url[1:]
|
||||||
|
loc = os.path.join(settings.MEDIA_ROOT, url)
|
||||||
|
if not os.path.exists(loc):
|
||||||
|
print("InvenTree: Generating thumbnail for Part '{p}'".format(p=part.name))
|
||||||
|
part.image.render_variations(replace=False)
|
||||||
|
except (OperationalError, ProgrammingError):
|
||||||
|
print("Could not generate Part thumbnails")
|
||||||
|
Loading…
Reference in New Issue
Block a user