Updated configuration using config.toml file instead of environment variables
This commit is contained in:
parent
bcbf33984b
commit
a06f49c2a5
3 changed files with 30 additions and 12 deletions
13
config.toml
Normal file
13
config.toml
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
secret_key = "dev_sDo6gl1Yf8GIE7XEA2B4xF841eMOpfG1"
|
||||||
|
debug = false
|
||||||
|
hosts = ["localhost"]
|
||||||
|
trusted_origins = ["http://localhost"]
|
||||||
|
time_zone = "CET"
|
||||||
|
|
||||||
|
[media]
|
||||||
|
root = "/var/lib/nummi"
|
||||||
|
|
||||||
|
[databases.default]
|
||||||
|
ENGINE = "django.db.backends.postgresql"
|
||||||
|
NAME = "nummi"
|
||||||
|
USER = "nummi"
|
|
@ -1,4 +0,0 @@
|
||||||
NUMMI_MEDIA_ROOT="/var/lib/nummi"
|
|
||||||
NUMMI_SECRET="xxxxxx"
|
|
||||||
#NUMMI_DEBUG="True"
|
|
||||||
NUMMI_HOST="nummi.edgarpierre.fr"
|
|
|
@ -10,12 +10,21 @@ For the full list of settings and their values, see
|
||||||
https://docs.djangoproject.com/en/4.0/ref/settings/
|
https://docs.djangoproject.com/en/4.0/ref/settings/
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import tomllib
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
CONFIG_PATH = os.environ.get("NUMMI_CONFIG", None)
|
||||||
|
if CONFIG_PATH is None:
|
||||||
|
CONFIG = dict()
|
||||||
|
else:
|
||||||
|
with open(CONFIG_PATH, "rb") as CONFIG_FILE:
|
||||||
|
CONFIG = tomllib.load(CONFIG_FILE)
|
||||||
|
|
||||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||||
|
MEDIA_CONF = CONFIG.get("media", {})
|
||||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||||
MEDIA_ROOT = Path(os.environ.get("NUMMI_MEDIA_ROOT", "/var/lib/nummi"))
|
MEDIA_ROOT = Path(MEDIA_CONF.get("root", "/var/lib/nummi"))
|
||||||
MEDIA_URL = "media/"
|
MEDIA_URL = "media/"
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,13 +32,13 @@ MEDIA_URL = "media/"
|
||||||
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/
|
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/
|
||||||
|
|
||||||
# SECURITY WARNING: keep the secret key used in production secret!
|
# SECURITY WARNING: keep the secret key used in production secret!
|
||||||
SECRET_KEY = os.environ.get("NUMMI_SECRET", "dev_sDo6gl1Yf8GIE7XEA2B4xF841eMOpfG1")
|
SECRET_KEY = CONFIG.get("secret_key", "dev_sDo6gl1Yf8GIE7XEA2B4xF841eMOpfG1")
|
||||||
|
|
||||||
# SECURITY WARNING: don't run with debug turned on in production!
|
# SECURITY WARNING: don't run with debug turned on in production!
|
||||||
DEBUG = os.environ.get("NUMMI_DEBUG", None) == "True"
|
DEBUG = CONFIG.get("debug", False)
|
||||||
|
|
||||||
ALLOWED_HOSTS = [os.environ.get("NUMMI_HOST", "localhost")]
|
ALLOWED_HOSTS = CONFIG.get("hosts", ["localhost"])
|
||||||
CSRF_TRUSTED_ORIGINS = [f"https://{os.environ.get('NUMMI_HOST', 'localhost')}"]
|
CSRF_TRUSTED_ORIGINS = CONFIG.get("trusted_origins", ["http://localhost"])
|
||||||
|
|
||||||
|
|
||||||
# Application definition
|
# Application definition
|
||||||
|
@ -78,13 +87,13 @@ WSGI_APPLICATION = "nummi.wsgi.application"
|
||||||
# Database
|
# Database
|
||||||
# https://docs.djangoproject.com/en/4.0/ref/settings/#databases
|
# https://docs.djangoproject.com/en/4.0/ref/settings/#databases
|
||||||
|
|
||||||
DATABASES = {
|
DATABASES = CONFIG.get("databases", {
|
||||||
"default": {
|
"default": {
|
||||||
"ENGINE": "django.db.backends.postgresql",
|
"ENGINE": "django.db.backends.postgresql",
|
||||||
"NAME": "nummi",
|
"NAME": "nummi",
|
||||||
"USER": "nummi",
|
"USER": "nummi",
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
|
||||||
|
|
||||||
# Password validation
|
# Password validation
|
||||||
|
@ -110,7 +119,7 @@ AUTH_PASSWORD_VALIDATORS = [
|
||||||
# https://docs.djangoproject.com/en/4.0/topics/i18n/
|
# https://docs.djangoproject.com/en/4.0/topics/i18n/
|
||||||
|
|
||||||
LANGUAGE_CODE = "fr-fr"
|
LANGUAGE_CODE = "fr-fr"
|
||||||
TIME_ZONE = "CET"
|
TIME_ZONE = CONFIG.get("time_zone", "CET")
|
||||||
USE_I18N = True
|
USE_I18N = True
|
||||||
USE_TZ = True
|
USE_TZ = True
|
||||||
LOCALE_PATHS = [
|
LOCALE_PATHS = [
|
||||||
|
|
Loading…
Reference in a new issue