1
Fork 0
e11sync/app/e11sync/settings.py

163 lines
4.4 KiB
Python

from pathlib import Path
from os import environ
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
_DEBUG = bool(environ.get('E11SYNC_DEBUG', False))
_COMPRESS_OFFLINE = bool(environ.get('E11SYNC_COMPRESS_OFFLINE', False))
_STATIC_ROOT = environ.get('E11SYNC_STATIC_ROOT', '/tmp/e11sync-static')
_GEOIP_PATH = environ.get('GEOIP_PATH')
if db := environ.get('E11SYNC_DATABASE_PATH'):
_DATABASE_PATH = db
else:
_DATABASE_PATH = BASE_DIR / 'db.sqlite3'
if secret_path := environ.get("E11SYNC_SECRET_KEY_PATH"):
with open(secret_path) as f:
_SECRET_KEY = f.read().strip()
secret_key_msg = "SECRET_KEY read from {}".format(secret_path)
else:
_SECRET_KEY = 'django-insecure-$e2!=indeed'
secret_key_msg = "SECRET_KEY is insecure"
# otherwise it gets printed twice
if not environ.get("E11SYNC_DEBUG_PRINTED"):
print("DEBUG={}".format(_DEBUG))
print(secret_key_msg)
print("COMPRESS_OFFLINE={}".format(_COMPRESS_OFFLINE))
print("STATIC_ROOT={}".format(_STATIC_ROOT))
print("GEOIP_PATH={}".format(_GEOIP_PATH))
print("DATABASE_PATH={}".format(_DATABASE_PATH))
environ["E11SYNC_DEBUG_PRINTED"] = "1"
#######################################
# No more side effects after this place
SECRET_KEY = _SECRET_KEY
DEBUG = _DEBUG
ALLOWED_HOSTS = ["127.0.0.1", "localhost", "11sync.net"]
INTERNAL_IPS = ["127.0.0.1"]
# Application definition
INSTALLED_APPS = (['debug_toolbar'] if DEBUG else []) + [
'compressor',
'signup.apps.SignupConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
MIDDLEWARE = (
['debug_toolbar.middleware.DebugToolbarMiddleware'] if DEBUG else []) + [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'e11sync.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'e11sync.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': _DATABASE_PATH,
}
}
_password_validators = [
'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
'django.contrib.auth.password_validation.MinimumLengthValidator',
'django.contrib.auth.password_validation.CommonPasswordValidator',
'django.contrib.auth.password_validation.NumericPasswordValidator',
]
AUTH_PASSWORD_VALIDATORS = [{'NAME': v} for v in _password_validators]
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_TZ = True
STATIC_URL = 'static/'
STATICFILES_FINDERS = [
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
"compressor.finders.CompressorFinder",
]
STATIC_ROOT = _STATIC_ROOT
# At the time of testing:
# main-full.css: 34K
# main-mini.css: 49K
# main-full.css.br: 5.0K
# main-mini.css.br: 7.1K
#
# Minifying those files will necessitate sourcemaps, which
# is not currently possible due to
# https://github.com/django-compressor/django-compressor/issues/438
# Since the savings with minification are not that huge, let's keep
# it a bir larger, but much simpler.
COMPRESS_ENABLED = True
COMPRESS_OFFLINE = _COMPRESS_OFFLINE
COMPRESS_FILTERS = {
'css': [],
'js': [],
}
COMPRESS_PRECOMPILERS = (
('text/x-scss', 'sass --no-source-map {infile} {outfile}'),
)
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"handlers": {
"console": {
"class": "logging.StreamHandler",
},
},
"root": {
"handlers": ["console"],
"level": "WARNING",
},
}
GEOIP_PATH = _GEOIP_PATH