2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-19 05:25:42 +00:00

Improve settings.py

- Load database config from either config.yaml or environment variables
- Mix and match, if you want!
- Move to use logging module rather than just printing stuff
- Error if required database parameters are not required
This commit is contained in:
Oliver Walters
2020-11-13 13:38:01 +11:00
parent 1d4b826d03
commit 0f42916521
9 changed files with 183 additions and 71 deletions

View File

@ -1,12 +1,16 @@
from __future__ import unicode_literals
import os
import logging
from django.db.utils import OperationalError, ProgrammingError
from django.apps import AppConfig
from django.conf import settings
logger = logging.getLogger(__name__)
class PartConfig(AppConfig):
name = 'part'
@ -27,7 +31,7 @@ class PartConfig(AppConfig):
from .models import Part
print("InvenTree: Checking Part image thumbnails")
logger.debug("InvenTree: Checking Part image thumbnails")
try:
for part in Part.objects.all():
@ -36,11 +40,11 @@ class PartConfig(AppConfig):
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))
logger.info("InvenTree: Generating thumbnail for Part '{p}'".format(p=part.name))
try:
part.image.render_variations(replace=False)
except FileNotFoundError:
print("Image file missing")
logger.warning("Image file missing")
part.image = None
part.save()
except (OperationalError, ProgrammingError):