settings.py 4.62 KB
Newer Older
Guilhem Saurel's avatar
Guilhem Saurel committed
1
import os
Guilhem Saurel's avatar
git    
Guilhem Saurel committed
2
from pathlib import Path
Guilhem Saurel's avatar
initial  
Guilhem Saurel committed
3

Guilhem Saurel's avatar
Guilhem Saurel committed
4
5
6
PROJECT = 'dashboard'
PROJECT_VERBOSE = PROJECT.capitalize()
SELF_MAIL = False
Guilhem Saurel's avatar
Guilhem Saurel committed
7
8
DOMAIN_NAME = os.environ.get('DOMAIN_NAME', 'local')
ALLOWED_HOSTS = [os.environ.get('ALLOWED_HOST', f'{PROJECT}.{DOMAIN_NAME}')]
Guilhem Saurel's avatar
Guilhem Saurel committed
9
ALLOWED_HOSTS += [f'www.{host}' for host in ALLOWED_HOSTS]
Guilhem Saurel's avatar
initial  
Guilhem Saurel committed
10

Guilhem Saurel's avatar
Guilhem Saurel committed
11
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
Guilhem Saurel's avatar
initial  
Guilhem Saurel committed
12
13


Guilhem Saurel's avatar
Guilhem Saurel committed
14
15
SECRET_KEY = os.environ['SECRET_KEY']
DEBUG = os.environ.get('DEBUG', 'False').lower() == 'true'
Guilhem Saurel's avatar
initial  
Guilhem Saurel committed
16

Guilhem Saurel's avatar
Guilhem Saurel committed
17
EMAIL_USE_SSL = True
Guilhem Saurel's avatar
Guilhem Saurel committed
18
EMAIL_HOST = os.environ.get('EMAIL_HOST', f'smtp.{DOMAIN_NAME}')
19
20
EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_HOST_PASSWORD', '')
EMAIL_USER = os.environ.get('EMAIL_USER', '')
Guilhem Saurel's avatar
Guilhem Saurel committed
21
22
EMAIL_PORT = os.environ.get('EMAIL_PORT', 465)
EMAIL_FQDN = os.environ.get('EMAIL_FQDN', ALLOWED_HOSTS[0] if SELF_MAIL else DOMAIN_NAME)
Guilhem Saurel's avatar
Guilhem Saurel committed
23
24
25
26
27
EMAIL_HOST_USER = f'{EMAIL_USER}@{EMAIL_FQDN}'
SERVER_EMAIL = f'{EMAIL_USER}+{PROJECT}@{EMAIL_FQDN}'
DEFAULT_FROM_EMAIL = f'{PROJECT_VERBOSE} <{EMAIL_USER}@{EMAIL_FQDN}>'
EMAIL_BACKEND = 'django.core.mail.backends.%s' % ('filebased.EmailBackend' if DEBUG else 'smtp.EmailBackend')
EMAIL_SUBJECT_PREFIX = f'[{PROJECT_VERBOSE}] '
Guilhem Saurel's avatar
initial  
Guilhem Saurel committed
28

Guilhem Saurel's avatar
Guilhem Saurel committed
29
30
31
ADMINS = ((os.environ.get('ADMIN_NAME', f'{PROJECT_VERBOSE} webmaster'),
           os.environ.get('ADMIN_MAIL', f'webmaster@{DOMAIN_NAME}')),)

Guilhem Saurel's avatar
initial  
Guilhem Saurel committed
32
33
34
35
36
37
38
39
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
Guilhem Saurel's avatar
drf    
Guilhem Saurel committed
40
    'rest_framework',
Guilhem Saurel's avatar
Guilhem Saurel committed
41
    'django_tables2',
Guilhem Saurel's avatar
Guilhem Saurel committed
42
    'django_filters',
43
    'bootstrap4',
Guilhem Saurel's avatar
use ndh    
Guilhem Saurel committed
44
    'ndh',
Guilhem Saurel's avatar
initial  
Guilhem Saurel committed
45
46
47
48
49
50
51
52
53
54
55
56
57
    'rainboard',
]

MIDDLEWARE = [
    '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',
]

Guilhem Saurel's avatar
Guilhem Saurel committed
58
ROOT_URLCONF = f'{PROJECT}.urls'
Guilhem Saurel's avatar
initial  
Guilhem Saurel committed
59
60
61
62
63
64
65
66
67
68

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
Guilhem Saurel's avatar
use ndh    
Guilhem Saurel committed
69
                'django.template.context_processors.i18n',
Guilhem Saurel's avatar
initial  
Guilhem Saurel committed
70
71
72
73
74
75
76
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

Guilhem Saurel's avatar
Guilhem Saurel committed
77
WSGI_APPLICATION = f'{PROJECT}.wsgi.application'
Guilhem Saurel's avatar
initial  
Guilhem Saurel committed
78

Guilhem Saurel's avatar
Guilhem Saurel committed
79
DB = os.environ.get('DB', 'db.sqlite3')
Guilhem Saurel's avatar
initial  
Guilhem Saurel committed
80
81
DATABASES = {
    'default': {
Guilhem Saurel's avatar
Guilhem Saurel committed
82
        'ENGINE': f'django.db.backends.sqlite3',
Guilhem Saurel's avatar
Guilhem Saurel committed
83
        'NAME': os.path.join(BASE_DIR, DB),
Guilhem Saurel's avatar
initial  
Guilhem Saurel committed
84
85
    }
}
Guilhem Saurel's avatar
Guilhem Saurel committed
86
87
88
if DB == 'postgres':
    DATABASES['default'].update(
        ENGINE='django.db.backends.postgresql',
Guilhem Saurel's avatar
Guilhem Saurel committed
89
90
91
92
        NAME=os.environ.get('POSTGRES_DB', DB),
        USER=os.environ.get('POSTGRES_USER', DB),
        HOST=os.environ.get('POSTGRES_HOST', DB),
        PASSWORD=os.environ['POSTGRES_PASSWORD'],
Guilhem Saurel's avatar
Guilhem Saurel committed
93
    )
Guilhem Saurel's avatar
initial  
Guilhem Saurel committed
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]

Guilhem Saurel's avatar
Guilhem Saurel committed
110
111
LANGUAGE_CODE = os.environ.get('LANGUAGE_CODE', 'fr-FR')
TIME_ZONE = os.environ.get('TIME_ZONE', 'Europe/Paris')
Guilhem Saurel's avatar
initial  
Guilhem Saurel committed
112
113
114
115
USE_I18N = True
USE_L10N = True
USE_TZ = True

Guilhem Saurel's avatar
Guilhem Saurel committed
116
SITE_ID = int(os.environ.get('SITE_ID', 1))
Guilhem Saurel's avatar
initial  
Guilhem Saurel committed
117

Guilhem Saurel's avatar
Guilhem Saurel committed
118
MEDIA_ROOT = '/srv/media/'
Guilhem Saurel's avatar
Guilhem Saurel committed
119
MEDIA_URL = '/media/'
Guilhem Saurel's avatar
Guilhem Saurel committed
120
121
STATIC_URL = '/static/'
STATIC_ROOT = '/srv/static/'
Guilhem Saurel's avatar
Guilhem Saurel committed
122

123
124
125
126
127
128
if os.environ.get('MEMCACHED', 'False').lower() == 'true':
    CACHES = {
        'default': {
            'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
            'LOCATION': 'memcached:11211',
        }
Guilhem Saurel's avatar
Guilhem Saurel committed
129
    }
Guilhem Saurel's avatar
Guilhem Saurel committed
130
131
132
133
134

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
Guilhem Saurel's avatar
Guilhem Saurel committed
135
        'null': {
Guilhem Saurel's avatar
Guilhem Saurel committed
136
            'level': 'DEBUG',
Guilhem Saurel's avatar
Guilhem Saurel committed
137
            'class': 'logging.NullHandler',
Guilhem Saurel's avatar
Guilhem Saurel committed
138
139
140
        },
    },
    'loggers': {
Guilhem Saurel's avatar
Guilhem Saurel committed
141
142
143
        'django.security.DisallowedHost': {
            'handlers': ['null'],
            'propagate': False,
Guilhem Saurel's avatar
Guilhem Saurel committed
144
145
146
        },
    },
}
Guilhem Saurel's avatar
git    
Guilhem Saurel committed
147

Guilhem Saurel's avatar
Guilhem Saurel committed
148
DJANGO_TABLES2_TEMPLATE = 'rainboard/tables.html'
Guilhem Saurel's avatar
git    
Guilhem Saurel committed
149
150
151
RAINBOARD_DATA = Path('/srv/dashboard')
RAINBOARD_GITS = RAINBOARD_DATA / 'repositories'
RAINBOARD_RPKG = RAINBOARD_DATA / 'robotpkg'
152
PRIVATE_REGISTRY = 'gepgitlab.laas.fr:4567'
153
PUBLIC_REGISTRY = 'eur0c.laas.fr:5000'