mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Load database settings from config.yaml file
- Provide an initial config file
This commit is contained in:
parent
1f9e6f4a68
commit
f36757c87b
1
.gitignore
vendored
1
.gitignore
vendored
@ -40,6 +40,7 @@ secret_key.txt
|
|||||||
# IDE / development files
|
# IDE / development files
|
||||||
.idea/
|
.idea/
|
||||||
*.code-workspace
|
*.code-workspace
|
||||||
|
.vscode/
|
||||||
|
|
||||||
# Coverage reports
|
# Coverage reports
|
||||||
.coverage
|
.coverage
|
||||||
|
@ -1,33 +1,42 @@
|
|||||||
"""
|
"""
|
||||||
Django settings for InvenTree project.
|
Django settings for InvenTree project.
|
||||||
|
|
||||||
Generated by 'django-admin startproject' using Django 1.10.6.
|
In practice the settings in this file should not be adjusted,
|
||||||
|
instead settings can be configured in the config.yaml file
|
||||||
|
located in the top level project directory.
|
||||||
|
|
||||||
For more information on this file, see
|
This allows implementation configuration to be hidden from source control,
|
||||||
https://docs.djangoproject.com/en/1.10/topics/settings/
|
as well as separate configuration parameters from the more complex
|
||||||
|
database setup in this file.
|
||||||
|
|
||||||
For the full list of settings and their values, see
|
|
||||||
https://docs.djangoproject.com/en/1.10/ref/settings/
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
import tempfile
|
import tempfile
|
||||||
|
import io
|
||||||
|
import yaml
|
||||||
|
|
||||||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
||||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
|
||||||
|
cfg_filename = os.path.join(BASE_DIR, 'config.yaml')
|
||||||
|
|
||||||
# Quick-start development settings - unsuitable for production
|
if not os.path.exists(cfg_filename):
|
||||||
# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/
|
CONFIG = {}
|
||||||
|
print("Warning: config.yaml not found - using default settings")
|
||||||
|
else:
|
||||||
|
with open(cfg_filename, 'r') as cfg:
|
||||||
|
CONFIG = yaml.safe_load(cfg)
|
||||||
|
|
||||||
# SECURITY WARNING: keep the secret key used in production secret!
|
# Read the autogenerated key-file
|
||||||
key_file = open(os.path.join(BASE_DIR, 'secret_key.txt'), 'r')
|
key_file = open(os.path.join(BASE_DIR, 'secret_key.txt'), 'r')
|
||||||
|
|
||||||
SECRET_KEY = key_file.read().strip()
|
SECRET_KEY = key_file.read().strip()
|
||||||
|
|
||||||
|
# Default action is to run the system in Debug mode
|
||||||
# SECURITY WARNING: don't run with debug turned on in production!
|
# SECURITY WARNING: don't run with debug turned on in production!
|
||||||
DEBUG = True
|
DEBUG = CONFIG.get('debug', True)
|
||||||
|
|
||||||
ALLOWED_HOSTS = ['*']
|
ALLOWED_HOSTS = ['*']
|
||||||
|
|
||||||
@ -85,14 +94,6 @@ LOGGING = {
|
|||||||
'class': 'logging.StreamHandler',
|
'class': 'logging.StreamHandler',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
# 'loggers': {
|
|
||||||
# 'ddjango.db.backends': {
|
|
||||||
# 'level': 'DEBUG',
|
|
||||||
# 'handlers': ['console',],
|
|
||||||
# 'propagate': True
|
|
||||||
# },
|
|
||||||
# },
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -108,7 +109,7 @@ MIDDLEWARE = [
|
|||||||
'InvenTree.middleware.AuthRequiredMiddleware',
|
'InvenTree.middleware.AuthRequiredMiddleware',
|
||||||
]
|
]
|
||||||
|
|
||||||
if DEBUG:
|
if CONFIG.get('log_queries', False):
|
||||||
MIDDLEWARE.append('InvenTree.middleware.QueryCountMiddleware')
|
MIDDLEWARE.append('InvenTree.middleware.QueryCountMiddleware')
|
||||||
|
|
||||||
ROOT_URLCONF = 'InvenTree.urls'
|
ROOT_URLCONF = 'InvenTree.urls'
|
||||||
@ -137,32 +138,21 @@ REST_FRAMEWORK = {
|
|||||||
'rest_framework.authentication.SessionAuthentication',
|
'rest_framework.authentication.SessionAuthentication',
|
||||||
'rest_framework.authentication.TokenAuthentication',
|
'rest_framework.authentication.TokenAuthentication',
|
||||||
)
|
)
|
||||||
# 'EXCEPTION_HANDLER': 'InvenTree.utils.api_exception_handler',
|
|
||||||
# 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
|
|
||||||
# 'PAGE_SIZE': 50,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WSGI_APPLICATION = 'InvenTree.wsgi.application'
|
WSGI_APPLICATION = 'InvenTree.wsgi.application'
|
||||||
|
|
||||||
|
DATABASES = {}
|
||||||
|
|
||||||
# Database
|
# Database backend selection
|
||||||
# https://docs.djangoproject.com/en/1.10/ref/settings/#databases
|
if 'database' in CONFIG:
|
||||||
|
DATABASES['default'] = CONFIG['database']
|
||||||
DATABASES = {
|
else:
|
||||||
'default': {
|
print("Warning: Database backend not specified - using default")
|
||||||
|
DATABASES['default'] = {
|
||||||
'ENGINE': 'django.db.backends.sqlite3',
|
'ENGINE': 'django.db.backends.sqlite3',
|
||||||
'NAME': os.path.join(BASE_DIR, 'inventree_db.sqlite3'),
|
'NAME': os.path.join(BASE_DIR, 'inventree_db.sqlite3'),
|
||||||
},
|
}
|
||||||
# TODO - Uncomment this when postgresql support is re-integrated
|
|
||||||
# 'postgresql': {
|
|
||||||
# 'ENGINE': 'django.db.backends.postgresql',
|
|
||||||
# 'NAME': 'inventree',
|
|
||||||
# 'USER': 'inventreeuser',
|
|
||||||
# 'PASSWORD': 'inventree',
|
|
||||||
# 'HOST': 'localhost',
|
|
||||||
# 'PORT': '',
|
|
||||||
# }
|
|
||||||
}
|
|
||||||
|
|
||||||
CACHES = {
|
CACHES = {
|
||||||
'default': {
|
'default': {
|
||||||
@ -177,7 +167,6 @@ CACHES = {
|
|||||||
|
|
||||||
QR_CODE_CACHE_ALIAS = 'qr-code'
|
QR_CODE_CACHE_ALIAS = 'qr-code'
|
||||||
|
|
||||||
|
|
||||||
# Password validation
|
# Password validation
|
||||||
# https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators
|
# https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators
|
||||||
|
|
||||||
|
20
InvenTree/config.yaml
Normal file
20
InvenTree/config.yaml
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
|
||||||
|
# Database backend selection - Configure backend database settings
|
||||||
|
# Ref: https://docs.djangoproject.com/en/2.2/ref/settings/#std:setting-DATABASES
|
||||||
|
# Specify database parameters below as they appear in the Django docs
|
||||||
|
database:
|
||||||
|
ENGINE: django.db.backends.sqlite3
|
||||||
|
NAME: inventree_db.sqlite3
|
||||||
|
|
||||||
|
# For more complex database installations, further parameters are required
|
||||||
|
# Refer to the django documentation for full list of options
|
||||||
|
# USER: db_username
|
||||||
|
# PASSWORD: db_password
|
||||||
|
# HOST: db_hostname
|
||||||
|
# PORT: db_port
|
||||||
|
|
||||||
|
# Set debug to False to run in production mode
|
||||||
|
debug: True
|
||||||
|
|
||||||
|
# Logging options
|
||||||
|
log_queries: False
|
Loading…
Reference in New Issue
Block a user