settings.py 4.59 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
19
20
21
22
EMAIL_HOST = os.environ.get('EMAIL_HOST', f'smtp.{DOMAIN_NAME}')
EMAIL_HOST_PASSWORD = os.environ['EMAIL_HOST_PASSWORD']
EMAIL_USER = os.environ.get('EMAIL_USER', 'majo')
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
Guilhem Saurel committed
40
    'django_tables2',
Guilhem Saurel's avatar
Guilhem Saurel committed
41
    'django_filters',
42
    'bootstrap4',
Guilhem Saurel's avatar
use ndh    
Guilhem Saurel committed
43
    'ndh',
Guilhem Saurel's avatar
initial  
Guilhem Saurel committed
44
45
46
47
48
49
50
51
52
53
54
55
56
    '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
57
ROOT_URLCONF = f'{PROJECT}.urls'
Guilhem Saurel's avatar
initial  
Guilhem Saurel committed
58
59
60
61
62
63
64
65
66
67

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

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

Guilhem Saurel's avatar
Guilhem Saurel committed
78
DB = os.environ.get('DB', 'db.sqlite3')
Guilhem Saurel's avatar
initial  
Guilhem Saurel committed
79
80
DATABASES = {
    'default': {
Guilhem Saurel's avatar
Guilhem Saurel committed
81
        'ENGINE': f'django.db.backends.sqlite3',
Guilhem Saurel's avatar
Guilhem Saurel committed
82
        'NAME': os.path.join(BASE_DIR, DB),
Guilhem Saurel's avatar
initial  
Guilhem Saurel committed
83
84
    }
}
Guilhem Saurel's avatar
Guilhem Saurel committed
85
86
87
if DB == 'postgres':
    DATABASES['default'].update(
        ENGINE='django.db.backends.postgresql',
Guilhem Saurel's avatar
Guilhem Saurel committed
88
89
90
91
        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
92
    )
Guilhem Saurel's avatar
initial  
Guilhem Saurel committed
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108

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
109
110
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
111
112
113
114
USE_I18N = True
USE_L10N = True
USE_TZ = True

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

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

122
123
124
125
126
127
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
128
    }
Guilhem Saurel's avatar
Guilhem Saurel committed
129
130
131
132
133

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

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