· 9 years ago · Sep 26, 2016, 01:46 PM
1import os
2
3# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
4BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
5
6# SECURITY WARNING: keep the secret key used in production secret!
7SECRET_KEY = '{{ openwisp2_secret_key }}'
8
9# SECURITY WARNING: don't run with debug turned on in production!
10DEBUG = False
11
12ALLOWED_HOSTS = [
13 '{{ inventory_hostname }}',
14{% for host in openwisp2_allowed_hosts %}
15 '{{ host }}',
16{% endfor %}
17]
18
19# Application definition
20
21INSTALLED_APPS = [
22 'django.contrib.auth',
23 'django.contrib.contenttypes',
24 'django.contrib.sessions',
25 'django.contrib.messages',
26 'django.contrib.staticfiles',
27 'django_netjsonconfig',
28 'django.contrib.admin',
29 'sortedm2m',
30 'reversion',
31 'django_x509',
32{% for app in openwisp2_extra_django_apps %}
33 '{{ app }}',
34{% endfor %}
35{% if openwisp2_sentry.get('dsn') %}
36 'raven.contrib.django.raven_compat',
37{% endif %}
38]
39
40MIDDLEWARE_CLASSES = [
41 'django.middleware.security.SecurityMiddleware',
42 'django.contrib.sessions.middleware.SessionMiddleware',
43 'django.middleware.common.CommonMiddleware',
44 'django.middleware.csrf.CsrfViewMiddleware',
45 'django.contrib.auth.middleware.AuthenticationMiddleware',
46 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
47 'django.contrib.messages.middleware.MessageMiddleware',
48 'django.middleware.clickjacking.XFrameOptionsMiddleware',
49]
50
51ROOT_URLCONF = 'openwisp2.urls'
52
53TEMPLATES = [
54 {
55 'BACKEND': 'django.template.backends.django.DjangoTemplates',
56 'DIRS': [],
57 'APP_DIRS': True,
58 'OPTIONS': {
59 'context_processors': [
60 'django.template.context_processors.debug',
61 'django.template.context_processors.request',
62 'django.contrib.auth.context_processors.auth',
63 'django.contrib.messages.context_processors.messages',
64 ],
65 },
66 },
67]
68
69WSGI_APPLICATION = 'openwisp2.wsgi.application'
70
71# Database
72# https://docs.djangoproject.com/en/1.9/ref/settings/#databases
73
74DATABASES = {
75 'default': {
76 'ENGINE': '{{ openwisp2_database.engine }}',
77 'NAME': '{{ openwisp2_database.name }}',
78{% if openwisp2_database.user %}
79 'USER': '{{ openwisp2_database.user }}',
80{% endif %}
81{% if openwisp2_database.password %}
82 'PASSWORD': '{{ openwisp2_database.password }}',
83{% endif %}
84{% if openwisp2_database.host %}
85 'HOST': '{{ openwisp2_database.host }}',
86{% endif %}
87{% if openwisp2_database.port %}
88 'PORT': '{{ openwisp2_database.port }}',
89{% endif %}
90{% if openwisp2_database.options %}
91 'OPTIONS': {{ openwisp2_database.options|to_nice_json }}
92{% endif %}
93 }
94}
95
96# Password validation
97# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators
98
99AUTH_PASSWORD_VALIDATORS = [
100 {
101 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
102 },
103 {
104 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
105 },
106 {
107 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
108 },
109 {
110 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
111 },
112]
113
114# Internationalization
115# https://docs.djangoproject.com/en/1.9/topics/i18n/
116
117LANGUAGE_CODE = '{{ openwisp2_language_code }}'
118TIME_ZONE = '{{ openwisp2_time_zone }}'
119USE_I18N = True
120USE_L10N = True
121USE_TZ = True
122
123# Static files (CSS, JavaScript, Images)
124# https://docs.djangoproject.com/en/1.9/howto/static-files/
125
126STATIC_ROOT = '%s/static' % BASE_DIR
127MEDIA_ROOT = '%s/media' % BASE_DIR
128STATIC_URL = '/static/'
129MEDIA_URL = '/media/'
130
131NETJSONCONFIG_SHARED_SECRET = '{{ openwisp2_shared_secret }}'
132{% if openwisp2_context %}
133NETJSONCONFIG_CONTEXT = {{ openwisp2_context|to_nice_json }}
134{% endif %}
135
136# django x509 settings
137DJANGO_X509_DEFAULT_CERT_VALIDITY = {{ openwisp2_default_cert_validity }}
138DJANGO_X509_DEFAULT_CA_VALIDITY = {{ openwisp2_default_ca_validity }}
139
140# See http://docs.djangoproject.com/en/dev/topics/logging for
141# more details on how to customize your logging configuration.
142LOGGING = {
143 'version': 1,
144 'disable_existing_loggers': False,
145 'filters': {
146 'require_debug_false': {
147 '()': 'django.utils.log.RequireDebugFalse',
148 },
149 'require_debug_true': {
150 '()': 'django.utils.log.RequireDebugTrue',
151 },
152 },
153 'formatters': {
154 'simple': {
155 'format': '[%(levelname)s] %(message)s'
156 },
157 'verbose': {
158 'format': '\n\n[%(levelname)s %(asctime)s] module: %(module)s, process: %(process)d, thread: %(thread)d\n%(message)s'
159 },
160 },
161 'handlers': {
162 'console': {
163 'level': 'DEBUG',
164 'class': 'logging.StreamHandler',
165 'filters': ['require_debug_true'],
166 'formatter': 'simple'
167 },
168 'mail_admins': {
169 'level': 'ERROR',
170 'filters': ['require_debug_false'],
171 'class': 'django.utils.log.AdminEmailHandler'
172 },
173 'main_log': {
174 'level': 'ERROR',
175 'class': 'logging.handlers.RotatingFileHandler',
176 'formatter': 'verbose',
177 'filename': os.path.join(BASE_DIR, 'log/error.log'),
178 'maxBytes': 5242880.0,
179 'backupCount': 3,
180 'formatter': 'verbose'
181 },
182{% if openwisp2_sentry.get('dsn') %}
183 'sentry': {
184 'level': 'WARNING',
185 'class': 'raven.contrib.django.raven_compat.handlers.SentryHandler',
186 'filters': ['require_debug_false']
187 },
188{% endif %}
189 },
190 'root': {
191 'level': 'INFO',
192 'handlers': [
193 'main_log',
194 'console',
195 'mail_admins',
196{% if openwisp2_sentry.get('dsn') %}
197 'sentry'
198{% endif %}
199 ]
200 }
201}
202
203{% if openwisp2_sentry.get('dsn') %}
204RAVEN_CONFIG = {{ openwisp2_sentry|to_nice_json }}
205{% endif %}