1
|
# Django settings for wcsinst project.
|
2
|
|
3
|
import os
|
4
|
from ConfigParser import SafeConfigParser
|
5
|
|
6
|
# get configuration files from :
|
7
|
# 1. default-settings.ini from source code
|
8
|
# 2. os.environ.get('SETTINGS_INI') if it exists
|
9
|
# else /etc/wcsinstd/settings.ini
|
10
|
# and then /etc/wcsinstd/local-settings.ini
|
11
|
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
12
|
SETTINGS_INI = (os.path.join(BASE_DIR, 'default-settings.ini'),)
|
13
|
if os.environ.get('SETTINGS_INI'):
|
14
|
SETTINGS_INI += (os.environ.get('SETTINGS_INI'),)
|
15
|
else:
|
16
|
ETC_DIR = os.path.join('/', 'etc', 'wcsinstd')
|
17
|
SETTINGS_INI += (
|
18
|
os.path.join(ETC_DIR, 'settings.ini'),
|
19
|
os.path.join(ETC_DIR, 'local-settings.ini')
|
20
|
)
|
21
|
|
22
|
config = SafeConfigParser()
|
23
|
config.read(SETTINGS_INI)
|
24
|
|
25
|
|
26
|
DEBUG = config.getboolean('debug', 'general')
|
27
|
INTERNAL_IPS = tuple(config.get('debug', 'internal_ips').split())
|
28
|
TEMPLATE_DEBUG = config.getboolean('debug', 'template')
|
29
|
ADMINS = tuple(config.items('admins'))
|
30
|
MANAGERS = tuple(config.items('managers'))
|
31
|
SENTRY_DSN = config.get('debug', 'sentry_dsn')
|
32
|
DEBUG_TOOLBAR = config.getboolean('debug', 'toolbar')
|
33
|
|
34
|
DATABASES = {
|
35
|
'default': {
|
36
|
'ENGINE': config.get('database', 'engine'),
|
37
|
'NAME': config.get('database','name'),
|
38
|
'USER': config.get('database','user'),
|
39
|
'PASSWORD': config.get('database','password'),
|
40
|
'HOST': config.get('database','host'),
|
41
|
'PORT': config.get('database','port'),
|
42
|
}
|
43
|
}
|
44
|
|
45
|
# Hosts/domain names that are valid for this site; required if DEBUG is False
|
46
|
# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
|
47
|
ALLOWED_HOSTS = ['*']
|
48
|
USE_X_FORWARDED_HOST = True
|
49
|
|
50
|
# Local time zone for this installation. Choices can be found here:
|
51
|
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
|
52
|
# although not all choices may be available on all operating systems.
|
53
|
# In a Windows environment this must be set to your system time zone.
|
54
|
TIME_ZONE = 'Europe/Paris'
|
55
|
|
56
|
# Language code for this installation. All choices can be found here:
|
57
|
# http://www.i18nguy.com/unicode/language-identifiers.html
|
58
|
LANGUAGE_CODE = 'fr-fr'
|
59
|
gettext_noop = lambda s: s
|
60
|
LANGUAGES = (
|
61
|
('en', gettext_noop('English')),
|
62
|
('fr', gettext_noop('French')),
|
63
|
)
|
64
|
|
65
|
SITE_ID = 1
|
66
|
|
67
|
# If you set this to False, Django will make some optimizations so as not
|
68
|
# to load the internationalization machinery.
|
69
|
USE_I18N = True
|
70
|
|
71
|
# If you set this to False, Django will not format dates, numbers and
|
72
|
# calendars according to the current locale.
|
73
|
USE_L10N = True
|
74
|
|
75
|
# If you set this to False, Django will not use timezone-aware datetimes.
|
76
|
USE_TZ = True
|
77
|
|
78
|
# Absolute filesystem path to the directory that will hold user-uploaded files.
|
79
|
# Example: "/var/www/example.com/media/"
|
80
|
MEDIA_ROOT = config.get('dirs','media_root')
|
81
|
|
82
|
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
|
83
|
# trailing slash.
|
84
|
# Examples: "http://example.com/media/", "http://media.example.com/"
|
85
|
MEDIA_URL = ''
|
86
|
|
87
|
# Absolute path to the directory static files should be collected to.
|
88
|
# Don't put anything in this directory yourself; store your static files
|
89
|
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
|
90
|
# Example: "/var/www/example.com/static/"
|
91
|
STATIC_ROOT = config.get('dirs','static_root')
|
92
|
|
93
|
# URL prefix for static files.
|
94
|
# Example: "http://example.com/static/", "http://static.example.com/"
|
95
|
STATIC_URL = '/static/'
|
96
|
|
97
|
# Additional locations of static files
|
98
|
STATICFILES_DIRS = tuple(config.get('dirs','static_dirs').split())
|
99
|
|
100
|
# List of finder classes that know how to find static files in
|
101
|
# various locations.
|
102
|
STATICFILES_FINDERS = (
|
103
|
'django.contrib.staticfiles.finders.FileSystemFinder',
|
104
|
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
|
105
|
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
|
106
|
)
|
107
|
|
108
|
# Make this unique, and don't share it with anybody.
|
109
|
SECRET_KEY = config.get('secrets', 'secret_key')
|
110
|
|
111
|
# List of callables that know how to import templates from various sources.
|
112
|
TEMPLATE_LOADERS = (
|
113
|
'django.template.loaders.filesystem.Loader',
|
114
|
'django.template.loaders.app_directories.Loader',
|
115
|
# 'django.template.loaders.eggs.Loader',
|
116
|
)
|
117
|
|
118
|
MIDDLEWARE_CLASSES = (
|
119
|
'django.middleware.common.CommonMiddleware',
|
120
|
'django.contrib.sessions.middleware.SessionMiddleware',
|
121
|
'django.middleware.csrf.CsrfViewMiddleware',
|
122
|
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
123
|
'django.contrib.messages.middleware.MessageMiddleware',
|
124
|
# Uncomment the next line for simple clickjacking protection:
|
125
|
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
126
|
)
|
127
|
|
128
|
# Python dotted path to the WSGI application used by Django's runserver.
|
129
|
WSGI_APPLICATION = 'wcsinst.wsgi.application'
|
130
|
|
131
|
TEMPLATE_DIRS = tuple(config.get('dirs', 'template_dirs').split())
|
132
|
|
133
|
INSTALLED_APPS = (
|
134
|
'south',
|
135
|
'django.contrib.auth',
|
136
|
'django.contrib.contenttypes',
|
137
|
'django.contrib.sessions',
|
138
|
'django.contrib.sites',
|
139
|
'django.contrib.messages',
|
140
|
'django.contrib.staticfiles',
|
141
|
'django.contrib.admin',
|
142
|
)
|
143
|
|
144
|
ROOT_URLCONF = 'wcsinst.urls'
|
145
|
|
146
|
if config.getboolean('cache', 'memcached'):
|
147
|
CACHES = {
|
148
|
'default': {
|
149
|
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
|
150
|
'LOCATION': '127.0.0.1:11211',
|
151
|
},
|
152
|
}
|
153
|
|
154
|
# A sample logging configuration. The only tangible logging
|
155
|
# performed by this configuration is to send an email to
|
156
|
# the site admins on every HTTP 500 error when DEBUG=False.
|
157
|
# See http://docs.djangoproject.com/en/dev/topics/logging for
|
158
|
# more details on how to customize your logging configuration.
|
159
|
LOGGING = {
|
160
|
'version': 1,
|
161
|
'disable_existing_loggers': False,
|
162
|
'filters': {
|
163
|
'require_debug_false': {
|
164
|
'()': 'django.utils.log.RequireDebugFalse'
|
165
|
}
|
166
|
},
|
167
|
'formatters': {
|
168
|
'verbose': {
|
169
|
'format': '[%(asctime)s] %(levelname)s %(name)s: %(message)s',
|
170
|
'datefmt': '%Y-%m-%d %a %H:%M:%S'
|
171
|
},
|
172
|
'syslog': {
|
173
|
'format': '%(levelname)s %(name)s: %(message)s',
|
174
|
},
|
175
|
},
|
176
|
'handlers': {
|
177
|
'console': {
|
178
|
'level': 'DEBUG',
|
179
|
'class':'logging.StreamHandler',
|
180
|
'formatter': 'verbose',
|
181
|
},
|
182
|
'mail_admins': {
|
183
|
'level': 'ERROR',
|
184
|
'filters': ['require_debug_false'],
|
185
|
'class': 'django.utils.log.AdminEmailHandler'
|
186
|
},
|
187
|
'syslog': {
|
188
|
'level': 'DEBUG',
|
189
|
'address': '/dev/log',
|
190
|
'class': 'logging.handlers.SysLogHandler',
|
191
|
'formatter': 'syslog',
|
192
|
},
|
193
|
},
|
194
|
'loggers': {
|
195
|
'django.request': {
|
196
|
'handlers': ['mail_admins'],
|
197
|
'level': 'ERROR',
|
198
|
'propagate': True,
|
199
|
},
|
200
|
'': {
|
201
|
'handlers': ['mail_admins', 'syslog', 'console'],
|
202
|
'level': 'INFO',
|
203
|
}
|
204
|
}
|
205
|
}
|
206
|
|
207
|
# debug settings
|
208
|
if DEBUG:
|
209
|
LOGGING['loggers']['']['level'] = 'DEBUG'
|
210
|
|
211
|
# email settings
|
212
|
EMAIL_HOST = config.get('email', 'host')
|
213
|
EMAIL_PORT = config.getint('email', 'port')
|
214
|
EMAIL_HOST_USER = config.get('email', 'user')
|
215
|
EMAIL_HOST_PASSWORD = config.get('email', 'password')
|
216
|
EMAIL_SUBJECT_PREFIX = config.get('email', 'subject_prefix')
|
217
|
EMAIL_USE_TLS = config.getboolean('email', 'use_tls')
|
218
|
SERVER_EMAIL = config.get('email', 'server_email')
|
219
|
DEFAULT_FROM_EMAIL = config.get('email', 'default_from_email')
|
220
|
|
221
|
# wcsinst / wcsintd settings
|
222
|
WCSINSTD_URL = os.environ.get('WCSINSTD_URL')
|
223
|
if WCSINSTD_URL:
|
224
|
INSTALLED_APPS += ('wcsinst.wcsinst',)
|
225
|
else:
|
226
|
INSTALLED_APPS += ('wcsinst.wcsinstd',)
|
227
|
WCSINST_URL_TEMPLATE = config.get('wcsinstd', 'url_template')
|
228
|
WCSINST_WCSCTL_SCRIPT = config.get('wcsinstd', 'wcsctl_script')
|
229
|
WCSINST_WCS_APP_DIR = config.get('wcsinstd', 'wcs_app_dir')
|
230
|
|
231
|
# debug toolbar needs more
|
232
|
if DEBUG_TOOLBAR:
|
233
|
DEBUG_TOOLBAR_CONFIG = {'INTERCEPT_REDIRECTS': False}
|
234
|
INSTALLED_APPS += ('debug_toolbar',)
|
235
|
MIDDLEWARE_CLASSES += ('debug_toolbar.middleware.DebugToolbarMiddleware',)
|
236
|
|
237
|
# sentry needs more
|
238
|
if SENTRY_DSN:
|
239
|
RAVEN_CONFIG = {'dsn': SENTRY_DSN}
|
240
|
INSTALLED_APPS += ('raven.contrib.django.raven_compat',)
|
241
|
LOGGING['handlers']['sentry'] = {
|
242
|
'level': 'ERROR',
|
243
|
'class': 'raven.contrib.django.raven_compat.handlers.SentryHandler',
|
244
|
}
|
245
|
LOGGING['loggers']['']['handlers'].append('sentry')
|
246
|
|
247
|
try:
|
248
|
from local_settings import *
|
249
|
except ImportError:
|
250
|
pass
|
251
|
|