2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-18 21:15:41 +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.apps import AppConfig
from django.db.utils import OperationalError, ProgrammingError
from django.conf import settings
logger = logging.getLogger(__name__)
class CompanyConfig(AppConfig):
name = 'company'
@ -21,7 +25,7 @@ class CompanyConfig(AppConfig):
from .models import Company
print("InvenTree: Checking Company image thumbnails")
logger.debug("Checking Company image thumbnails")
try:
for company in Company.objects.all():
@ -30,11 +34,11 @@ class CompanyConfig(AppConfig):
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))
logger.info("InvenTree: Generating thumbnail for Company '{c}'".format(c=company.name))
try:
company.image.render_variations(replace=False)
except FileNotFoundError:
print("Image file missing")
logger.warning("Image file missing")
company.image = None
company.save()
except (OperationalError, ProgrammingError):