settings.py 4.35 KB
Newer Older
Guilhem Saurel's avatar
Guilhem Saurel committed
1
2
from os import environ
from os.path import abspath, dirname, join
Guilhem Saurel's avatar
git    
Guilhem Saurel committed
3
from pathlib import Path
Guilhem Saurel's avatar
initial  
Guilhem Saurel committed
4

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

Guilhem Saurel's avatar
Guilhem Saurel committed
12
BASE_DIR = dirname(dirname(abspath(__file__)))
Guilhem Saurel's avatar
initial  
Guilhem Saurel committed
13
14


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

Guilhem Saurel's avatar
Guilhem Saurel committed
18
19
20
21
22
23
24
25
26
27
28
EMAIL_USE_SSL = True
EMAIL_HOST = environ.get('EMAIL_HOST', f'smtp.{DOMAIN_NAME}')
EMAIL_HOST_PASSWORD = environ['EMAIL_HOST_PASSWORD']
EMAIL_USER = environ.get('EMAIL_USER', 'majo')
EMAIL_PORT = environ.get('EMAIL_PORT', 465)
EMAIL_FQDN = environ.get('EMAIL_FQDN', ALLOWED_HOSTS[0] if SELF_MAIL else DOMAIN_NAME)
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
29
30
31
32
33
34
35
36
37

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
Guilhem Saurel committed
38
    'django_tables2',
Guilhem Saurel's avatar
Guilhem Saurel committed
39
    'django_filters',
40
    'bootstrap4',
Guilhem Saurel's avatar
use ndh    
Guilhem Saurel committed
41
    'ndh',
Guilhem Saurel's avatar
initial  
Guilhem Saurel committed
42
43
44
45
46
47
48
49
50
51
52
53
54
    '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
55
ROOT_URLCONF = f'{PROJECT}.urls'
Guilhem Saurel's avatar
initial  
Guilhem Saurel committed
56
57
58
59
60
61
62
63
64
65

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
66
                'django.template.context_processors.i18n',
Guilhem Saurel's avatar
initial  
Guilhem Saurel committed
67
68
69
70
71
72
73
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

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

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

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
107
108
LANGUAGE_CODE = environ.get('LANGUAGE_CODE', 'fr-FR')
TIME_ZONE = environ.get('TIME_ZONE', 'Europe/Paris')
Guilhem Saurel's avatar
initial  
Guilhem Saurel committed
109
110
111
112
USE_I18N = True
USE_L10N = True
USE_TZ = True

Guilhem Saurel's avatar
Guilhem Saurel committed
113
SITE_ID = int(environ.get('SITE_ID', 1))
Guilhem Saurel's avatar
initial  
Guilhem Saurel committed
114

Guilhem Saurel's avatar
Guilhem Saurel committed
115
MEDIA_ROOT = '/srv/media/'
Guilhem Saurel's avatar
Guilhem Saurel committed
116
MEDIA_URL = '/media/'
Guilhem Saurel's avatar
Guilhem Saurel committed
117
118
STATIC_URL = '/static/'
STATIC_ROOT = '/srv/static/'
Guilhem Saurel's avatar
Guilhem Saurel committed
119

Guilhem Saurel's avatar
Guilhem Saurel committed
120
121
122
123
124
125
CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
        'LOCATION': 'memcached:11211',
    }
}
Guilhem Saurel's avatar
Guilhem Saurel committed
126
127
128
129
130

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

Guilhem Saurel's avatar
Guilhem Saurel committed
144
DJANGO_TABLES2_TEMPLATE = 'rainboard/tables.html'
Guilhem Saurel's avatar
git    
Guilhem Saurel committed
145
146
147
RAINBOARD_DATA = Path('/srv/dashboard')
RAINBOARD_GITS = RAINBOARD_DATA / 'repositories'
RAINBOARD_RPKG = RAINBOARD_DATA / 'robotpkg'
148
149
PRIVATE_REGISTRY = 'eur0c.laas.fr:4567'
PUBLIC_REGISTRY = 'eur0c.laas.fr:5000'