Use python-decouple instead of custom hack

This commit is contained in:
Rodolphe Breard 2018-02-09 18:52:37 +01:00
parent d5744c3842
commit af1a793965
3 changed files with 45 additions and 43 deletions

View file

@ -8,6 +8,7 @@ name = "pypi"
[packages]
django = "*"
python-decouple = "*"
[dev-packages]

32
Pipfile.lock generated
View file

@ -1,7 +1,7 @@
{
"_meta": {
"hash": {
"sha256": "8b5635a4f7b069ae6661115b9eaa15466f7cd96794af5d131735a3638be101fb"
"sha256": "c9096173a460c37db5cae58c8f61c3371b5e1fe5d436ccc27c29091ebd06fc4f"
},
"host-environment-markers": {
"implementation_name": "cpython",
@ -9,9 +9,9 @@
"os_name": "posix",
"platform_machine": "x86_64",
"platform_python_implementation": "CPython",
"platform_release": "4.14.15-1-ARCH",
"platform_release": "4.15.1-2-ARCH",
"platform_system": "Linux",
"platform_version": "#1 SMP PREEMPT Tue Jan 23 21:49:25 UTC 2018",
"platform_version": "#1 SMP Sun Feb 4 22:27:45 UTC 2018",
"python_full_version": "3.6.4",
"python_version": "3.6",
"sys_platform": "linux"
@ -34,19 +34,25 @@
],
"version": "==2.0.2"
},
"python-decouple": {
"hashes": [
"sha256:1317df14b43efee4337a4aa02914bf004f010cd56d6c4bd894e6474ec8c4fe2d"
],
"version": "==3.1"
},
"pytz": {
"hashes": [
"sha256:80af0f3008046b9975242012a985f04c5df1f01eed4ec1633d56cc47a75a6a48",
"sha256:feb2365914948b8620347784b6b6da356f31c9d03560259070b2f30cff3d469d",
"sha256:59707844a9825589878236ff2f4e0dc9958511b7ffaae94dc615da07d4a68d33",
"sha256:d0ef5ef55ed3d37854320d4926b04a4cb42a2e88f71da9ddfdacfde8e364f027",
"sha256:c41c62827ce9cafacd6f2f7018e4f83a6f1986e87bfd000b8cfbd4ab5da95f1a",
"sha256:8cc90340159b5d7ced6f2ba77694d946fc975b09f1a51d93f3ce3bb399396f94",
"sha256:dd2e4ca6ce3785c8dd342d1853dd9052b19290d5bf66060846e5dc6b8d6667f7",
"sha256:699d18a2a56f19ee5698ab1123bbcc1d269d061996aeb1eda6d89248d3542b82",
"sha256:fae4cffc040921b8a2d60c6cf0b5d662c1190fe54d718271db4eb17d44a185b7"
"sha256:ed6509d9af298b7995d69a440e2822288f2eca1681b8cce37673dbb10091e5fe",
"sha256:f93ddcdd6342f94cea379c73cddb5724e0d6d0a1c91c9bdef364dc0368ba4fda",
"sha256:61242a9abc626379574a166dc0e96a66cd7c3b27fc10868003fa210be4bff1c9",
"sha256:ba18e6a243b3625513d85239b3e49055a2f0318466e0b8a92b8fb8ca7ccdf55f",
"sha256:07edfc3d4d2705a20a6e99d97f0c4b61c800b8232dc1c04d87e8554f130148dd",
"sha256:3a47ff71597f821cd84a162e71593004286e5be07a340fd462f0d33a760782b5",
"sha256:5bd55c744e6feaa4d599a6cbd8228b4f8f9ba96de2c38d56f08e534b3c9edf0d",
"sha256:887ab5e5b32e4d0c86efddd3d055c1f363cbaa583beb8da5e22d2fa2f64d51ef",
"sha256:410bcd1d6409026fbaa65d9ed33bf6dd8b1e94a499e32168acfc7b332e4095c0"
],
"version": "==2017.3"
"version": "==2018.3"
}
},
"develop": {}

View file

@ -12,16 +12,10 @@ https://docs.djangoproject.com/en/2.0/ref/settings/
from django.utils.translation import gettext_lazy as _
from django.urls import reverse_lazy
from decouple import config
import os
def get_config_bool(env_name, default=False):
val = os.getenv(env_name, default='').lower()
if val == '':
return default
return val in ('true', '1', 't', 'y', 'yes')
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@ -30,13 +24,13 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.getenv('KHAGANAT_SECRET_KEY')
SECRET_KEY = config('KHAGANAT_SECRET_KEY')
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = get_config_bool('KHAGANAT_DEBUG', default=False)
DEBUG = config('KHAGANAT_DEBUG', default=False, cast=bool)
ALLOWED_HOSTS = [
_ for _ in os.getenv('KHAGANAT_HOSTNAMES', default='').split(',')
_ for _ in config('KHAGANAT_HOSTNAMES', default='').split(',')
if _ != ''
]
@ -103,14 +97,14 @@ DATABASES = {
# Emailing
# https://docs.djangoproject.com/fr/2.0/topics/email/
EMAIL_HOST = os.getenv('KHAGANAT_EMAIL_HOST', default='localhost')
EMAIL_PORT = int(os.getenv('KHAGANAT_EMAIL_PORT', default='25'))
EMAIL_HOST_USER = os.getenv('KHAGANAT_EMAIL_HOST_USER', default='')
EMAIL_HOST_PASSWORD = os.getenv('KHAGANAT_EMAIL_HOST_PASSWORD', default='')
EMAIL_USE_TLS = get_config_bool('KHAGANAT_EMAIL_USE_TLS', default=False)
EMAIL_HOST = config('KHAGANAT_EMAIL_HOST', default='localhost')
EMAIL_PORT = config('KHAGANAT_EMAIL_PORT', default=25, cast=int)
EMAIL_HOST_USER = config('KHAGANAT_EMAIL_HOST_USER', default='')
EMAIL_HOST_PASSWORD = config('KHAGANAT_EMAIL_HOST_PASSWORD', default='')
EMAIL_USE_TLS = config('KHAGANAT_EMAIL_USE_TLS', default=False, cast=bool)
EMAIL_SUBJECT_PREFIX = os.getenv('KHAGANAT_EMAIL_SUBJECT_PREFIX', default='')
DEFAULT_FROM_EMAIL = os.getenv(
EMAIL_SUBJECT_PREFIX = config('KHAGANAT_EMAIL_SUBJECT_PREFIX', default='')
DEFAULT_FROM_EMAIL = config(
'KHAGANAT_DEFAULT_FROM_EMAIL',
default='no-reply@localhost'
)
@ -120,13 +114,14 @@ DEFAULT_FROM_EMAIL = os.getenv(
# https://docs.djangoproject.com/en/2.0/topics/auth/customizing/
AUTH_USER_MODEL = 'neluser.NelUser'
LOGIN_URL = os.getenv('KHAGANAT_LOGIN_URL', default='/account/login/')
LOGIN_URL = config('KHAGANAT_LOGIN_URL', default='/account/login/')
LOGIN_REDIRECT_URL = reverse_lazy(
os.getenv('KHAGANAT_LOGIN_REDIRECT_URL', default='index')
config('KHAGANAT_LOGIN_REDIRECT_URL', default='index')
)
REGISTER_REQUIRE_VALIDATION = get_config_bool(
REGISTER_REQUIRE_VALIDATION = config(
'KHAGANAT_REGISTER_REQUIRE_VALIDATION',
default=True
default=True,
cast=bool
)
@ -152,7 +147,7 @@ AUTH_PASSWORD_VALIDATORS = [
# Internationalization
# https://docs.djangoproject.com/en/2.0/topics/i18n/
LANGUAGE_CODE = os.getenv('KHAGANAT_LANGUAGE_CODE', default='fr')
LANGUAGE_CODE = config('KHAGANAT_LANGUAGE_CODE', default='fr')
# https://github.com/django/django/blob/master/django/conf/global_settings.py
@ -161,7 +156,7 @@ LANGUAGES = [
('fr', _('French')),
]
TIME_ZONE = os.getenv('KHAGANAT_TIME_ZONE', default='Europe/Paris')
TIME_ZONE = config('KHAGANAT_TIME_ZONE', default='Europe/Paris')
USE_I18N = True
@ -173,20 +168,20 @@ USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.0/howto/static-files/
STATIC_URL = os.getenv('KHAGANAT_STATIC_URL', default='/static/')
STATIC_ROOT = os.getenv('KHAGANAT_STATIC_ROOT', default='') or None
STATIC_URL = config('KHAGANAT_STATIC_URL', default='/static/')
STATIC_ROOT = config('KHAGANAT_STATIC_ROOT', default='') or None
# Logs configuration
KHAGANAT_LOGS_MIN_DAYS = int(os.getenv('KHAGANAT_LOGS_MIN_DAYS', default='0'))
KHAGANAT_LOGS_MAX_DAYS = int(os.getenv('KHAGANAT_LOGS_MAX_DAYS', default='7'))
KHAGANAT_LOGS_MIN_DAYS = config('KHAGANAT_LOGS_MIN_DAYS', default=0, cast=int)
KHAGANAT_LOGS_MAX_DAYS = config('KHAGANAT_LOGS_MAX_DAYS', default=7, cast=int)
# TLS
# https://docs.djangoproject.com/fr/2.0/ref/settings/#std:setting-SECURE_PROXY_SSL_HEADER
if get_config_bool('KHAGANAT_FORCE_HTTPS', default=False):
if config('KHAGANAT_FORCE_HTTPS', default=False, cast=bool):
SECURE_PROXY_SSL_HEADER = (
os.getenv('KHAGANAT_HTTPS_HEADER_NAME', default='HTTP_X_FORWARDED_PROTO'),
os.getenv('KHAGANAT_HTTPS_HEADER_VALUE', default='https')
config('KHAGANAT_HTTPS_HEADER_NAME', default='HTTP_X_FORWARDED_PROTO'),
config('KHAGANAT_HTTPS_HEADER_VALUE', default='https')
)