Remove instance-specific data from settings.py

newer-dal
LEdoian 3 years ago
parent 32402aba3e
commit 38fa3f0795

@ -13,20 +13,11 @@ https://docs.djangoproject.com/en/3.1/ref/settings/
from pathlib import Path from pathlib import Path
from os.path import isfile from os.path import isfile
SECRETS_FILE = '~/wish.secrets' DEBUG = True
# FIXME: What if the secret key is not found or not read! # Bad, old, already has been in Git...
if isfile(SECRETS_FILE): SECRET_KEY = 'h-mqswfvdslj#c@p264l*@qpsmsj6$$c052dsrh7a^(uza4q2a'
with open(SECRETS_FILE, "r") as f: ALLOWED_HOSTS = []
DEBUG = False EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
SECRET_KEY = f.readline().strip()
ALLOWED_HOSTS = ['wish.ledoian.cz']
print("Running in production")
else:
DEBUG = True
# Bad, old, already has been in Git...
SECRET_KEY = 'h-mqswfvdslj#c@p264l*@qpsmsj6$$c052dsrh7a^(uza4q2a'
ALLOWED_HOSTS = []
print("TEST SERVER!")
# Build paths inside the project like this: BASE_DIR / 'subdir'. # Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent BASE_DIR = Path(__file__).resolve().parent.parent
@ -93,22 +84,12 @@ WSGI_APPLICATION = 'wish.wsgi.application'
# Database # Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases # https://docs.djangoproject.com/en/3.1/ref/settings/#databases
if DEBUG: DATABASES = {
DATABASES = { 'default': {
'default': { 'ENGINE': 'django.db.backends.sqlite3',
'ENGINE': 'django.db.backends.sqlite3', 'NAME': BASE_DIR / 'db.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
} }
else: }
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'wish',
'USER': 'wish',
}
}
# Password validation # Password validation
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators # https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators
@ -147,3 +128,23 @@ USE_TZ = True
# https://docs.djangoproject.com/en/3.1/howto/static-files/ # https://docs.djangoproject.com/en/3.1/howto/static-files/
AUTH_USER_MODEL = 'utils.MyUser' AUTH_USER_MODEL = 'utils.MyUser'
SECRETS_FILE = '~/wish.secrets'
# Override settings
if isfile(SECRETS_FILE):
with open(SECRETS_FILE, "r") as f:
exec(f.read())
# verify that required variables are set
print('TEST SERVER' if DEBUG else 'Production server')
if not DEBUG:
for var in [
'SECRET_KEY',
'ALLOWED_HOSTS',
'EMAIL_BACKEND',
'DEFAULT_FROM_EMAIL',
'SERVER_EMAIL',
]:
if var not in dir():
raise ValueError(f'Required variable {var} not defined')

Loading…
Cancel
Save