mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Check if Company thumbnails are created on Company app start
This commit is contained in:
parent
1a233e7949
commit
e0655f61d8
@ -1,7 +1,36 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.apps import AppConfig
|
import os
|
||||||
|
|
||||||
|
from django.apps import AppConfig
|
||||||
|
from django.db.utils import OperationalError, ProgrammingError
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
class CompanyConfig(AppConfig):
|
class CompanyConfig(AppConfig):
|
||||||
name = 'company'
|
name = 'company'
|
||||||
|
|
||||||
|
def ready(self):
|
||||||
|
"""
|
||||||
|
This function is called whenever the Company app is loaded.
|
||||||
|
"""
|
||||||
|
|
||||||
|
self.generate_company_thumbs()
|
||||||
|
|
||||||
|
def generate_company_thumbs(self):
|
||||||
|
|
||||||
|
from .models import Company
|
||||||
|
|
||||||
|
print("InvenTree: 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):
|
||||||
|
print("InvenTree: Generating thumbnail for Company '{c}'".format(c=company.name))
|
||||||
|
company.image.render_variations(replace=False)
|
||||||
|
except (OperationalError, ProgrammingError):
|
||||||
|
print("Could not generate Company thumbnails")
|
||||||
|
|
@ -96,7 +96,7 @@ class Company(models.Model):
|
|||||||
upload_to=rename_company_image,
|
upload_to=rename_company_image,
|
||||||
null=True,
|
null=True,
|
||||||
blank=True,
|
blank=True,
|
||||||
variations={'thumnbnail': (128, 128)},
|
variations={'thumbnail': (128, 128)},
|
||||||
delete_orphans=True,
|
delete_orphans=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -20,13 +20,14 @@ class PartConfig(AppConfig):
|
|||||||
def generate_part_thumbnails(self):
|
def generate_part_thumbnails(self):
|
||||||
from .models import Part
|
from .models import Part
|
||||||
|
|
||||||
print("Checking Part image thumbnails")
|
print("InvenTree: Checking Part image thumbnails")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for part in Part.objects.all():
|
for part in Part.objects.all():
|
||||||
if part.image:
|
if part.image:
|
||||||
url = part.image.thumbnail.name
|
url = part.image.thumbnail.name
|
||||||
loc = os.path.join(settings.MEDIA_ROOT, url)
|
loc = os.path.join(settings.MEDIA_ROOT, url)
|
||||||
|
|
||||||
if not os.path.exists(loc):
|
if not os.path.exists(loc):
|
||||||
print("InvenTree: Generating thumbnail for Part '{p}'".format(p=part.name))
|
print("InvenTree: Generating thumbnail for Part '{p}'".format(p=part.name))
|
||||||
part.image.render_variations(replace=False)
|
part.image.render_variations(replace=False)
|
||||||
|
Loading…
Reference in New Issue
Block a user