-
Notifications
You must be signed in to change notification settings - Fork 113
/
settings.py
executable file
·407 lines (346 loc) · 12.9 KB
/
settings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
import os
import sys
from datetime import timedelta
from django.conf import settings
DEBUG = settings.DEBUG
SERVE_STATIC = DEBUG
TEMPLATE_DEBUG = DEBUG
USE_I18N = True
USE_L10N = True
USE_TZ = True
PROTOCOL = 'http' if DEBUG else 'https'
PORT = getattr(settings, 'PORT', '8000') if DEBUG else None
if PORT and str(PORT) not in ['80', '443']:
PORT_STRING = ':%s' % PORT
else:
PORT_STRING = ''
SUBDIR = getattr(settings, 'SUBDIR', '')
if SUBDIR and not SUBDIR.startswith('/'):
SUBDIR = '/%s' % SUBDIR
elif SUBDIR and SUBDIR.endswith('/'):
SUBDIR = SUBDIR[0:-1]
SITE_URL = '%s://%s%s%s' % (PROTOCOL, settings.DOMAIN, PORT_STRING, SUBDIR)
SITE_NAME = getattr(settings, 'SITE_NAME', 'Nodeshot')
MEDIA_ROOT = '%s/media/' % settings.SITE_ROOT
MEDIA_URL = '%s/media/' % SITE_URL
STATIC_ROOT = '%s/static/' % settings.SITE_ROOT
STATIC_URL = '%s/static/' % SITE_URL
ALLOWED_HOSTS = ['*']
if PROTOCOL == 'https':
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
os.environ['HTTPS'] = 'on'
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'raven.contrib.django.raven_compat.middleware.SentryResponseErrorIdMiddleware', # sentry
'raven.contrib.django.raven_compat.middleware.Sentry404CatchMiddleware', # sentry
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'corsheaders.middleware.CorsMiddleware',
)
TEMPLATE_CONTEXT_PROCESSORS = (
"django.contrib.auth.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.request",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.core.context_processors.static",
"django.core.context_processors.tz",
"django.contrib.messages.context_processors.messages",
"social.apps.django_app.context_processors.backends",
"social.apps.django_app.context_processors.login_redirect",
)
INSTALLED_APPS = [
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.gis',
# hstore support
'django_hstore',
# celery django email backend
'djcelery_email',
# nodeshot
'nodeshot.core.api',
'nodeshot.core.layers',
'nodeshot.core.nodes',
'nodeshot.core.cms',
'nodeshot.core.websockets',
'nodeshot.interop.sync',
'nodeshot.ui.default',
'nodeshot.community.participation',
'nodeshot.community.notifications',
'nodeshot.community.profiles',
'nodeshot.community.mailing',
'nodeshot.networking.net',
'nodeshot.networking.links',
'nodeshot.networking.services',
'nodeshot.networking.hardware',
'nodeshot.networking.connectors',
'nodeshot.interop.open311',
'nodeshot.ui.open311_demo',
# admin site
'grappelli.dashboard',
'grappelli',
'filebrowser',
'django.contrib.admin',
# 3d parthy django apps
'rest_framework',
'rest_framework_swagger',
'leaflet',
'south',
'smuggler',
'reversion',
'corsheaders',
'social.apps.django_app.default',
'rosetta',
# other utilities
'django_extensions',
'debug_toolbar',
]
AUTH_USER_MODEL = 'profiles.Profile'
if getattr(settings, 'RAVEN_CONFIG', {}):
INSTALLED_APPS.append('raven.contrib.django.raven_compat')
if 'old_nodeshot' in settings.DATABASES:
INSTALLED_APPS.append('nodeshot.interop.oldimporter')
DATABASE_ROUTERS = [
'nodeshot.interop.oldimporter.db.DefaultRouter',
'nodeshot.interop.oldimporter.db.OldNodeshotRouter'
]
# ------ FILEBROWSER ------ #
FILEBROWSER_DIRECTORY = ''
# ------ DJANGO CACHE ------ #
CACHES = {
'rosetta': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
'LOCATION': 'rosetta'
}
}
if DEBUG:
CACHES['default'] = {
'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
}
else:
CACHES['default'] = {
'BACKEND': 'django_redis.cache.RedisCache',
'LOCATION': '127.0.0.1:6379:1',
'OPTIONS': {
'CLIENT_CLASS': 'django_redis.client.DefaultClient',
}
}
SESSION_ENGINE = 'django.contrib.sessions.backends.cache'
SESSION_CACHE_ALIAS = 'default'
# ------ EMAIL SETTINGS ------ #
EMAIL_PORT = 1025 if DEBUG else 25 # 1025 if you are in development mode, while 25 is usually the production port
# ------ LOGGING ------ #
# See http://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'root': {
'level': 'WARNING',
'handlers': ['sentry'],
},
'formatters': {
'verbose': {
'format': '\n\n[%(levelname)s %(asctime)s] module: %(module)s, process: %(process)d, thread: %(thread)d\n%(message)s'
},
},
'handlers': {
'sentry': {
'level': 'ERROR',
'class': 'raven.contrib.django.raven_compat.handlers.SentryHandler',
},
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'verbose'
},
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
},
'logfile': {
'level': 'ERROR',
'class': 'logging.handlers.RotatingFileHandler',
'formatter': 'verbose',
'filename': settings.SITE_ROOT + "/../log/nodeshot.error.log",
'maxBytes': 10485760, # 10 MB
'backupCount': 3,
'formatter': 'verbose'
},
},
'loggers': {
'django': {
'handlers': ['logfile'],
'level': 'ERROR',
'propagate': True,
},
'django.request': {
'handlers': ['mail_admins', 'logfile'],
'level': 'ERROR',
'propagate': True,
},
'': {
'handlers': ['logfile'],
'level': 'ERROR',
},
'django.db.backends': {
'level': 'ERROR',
'handlers': ['console'],
'propagate': False,
},
'raven': {
'level': 'DEBUG',
'handlers': ['console'],
'propagate': False,
},
'sentry.errors': {
'level': 'DEBUG',
'handlers': ['console'],
'propagate': False,
}
}
}
# ------ CELERY ------ #
if DEBUG:
# this app makes it possible to use django as a queue system for celery
# so you don't need to install RabbitQM or Redis
# pretty cool for development, but might not suffice for production if your system is heavily used
# our suggestion is to switch only if you start experiencing issues
INSTALLED_APPS.append('kombu.transport.django')
BROKER_URL = 'django://'
# synchronous behaviour for development
# more info here: http://docs.celeryproject.org/en/latest/configuration.html#celery-always-eager
CELERY_ALWAYS_EAGER = True
CELERY_EAGER_PROPAGATES_EXCEPTIONS = True
else:
# in production the default background queue manager is Redis
BROKER_URL = 'redis://localhost:6379/0'
CELERY_RESULT_BACKEND = 'redis://localhost:6379/0'
BROKER_TRANSPORT_OPTIONS = {
"visibility_timeout": 3600, # 1 hour
"fanout_prefix": True
}
# in production emails are sent in the background
EMAIL_BACKEND = 'djcelery_email.backends.CeleryEmailBackend'
CELERYBEAT_SCHEDULE = {
'purge_notifications': {
'task': 'nodeshot.community.notifications.tasks.purge_notifications',
'schedule': timedelta(days=1),
}
}
# ------ GRAPPELLI ------ #
if 'grappelli' in INSTALLED_APPS:
GRAPPELLI_ADMIN_TITLE = '<a href="%s">%s Admin</a>' % (SITE_URL, SITE_NAME)
GRAPPELLI_INDEX_DASHBOARD = 'nodeshot.dashboard.NodeshotDashboard'
# ------ DEBUG TOOLBAR ------ #
INTERNAL_IPS = ('127.0.0.1', '::1',) # ip addresses where you want to show the debug toolbar here
DEBUG_TOOLBAR_CONFIG = {
'INTERCEPT_REDIRECTS': False,
}
# ------ UNIT TESTING SPEED UP ------ #
SOUTH_DATABASE_ADAPTERS = {'default': 'south.db.postgresql_psycopg2'}
SOUTH_TESTS_MIGRATE = False
if 'test' in sys.argv:
CELERY_ALWAYS_EAGER = True
PASSWORD_HASHERS = (
'django.contrib.auth.hashers.MD5PasswordHasher',
'django.contrib.auth.hashers.SHA1PasswordHasher',
'django.contrib.auth.hashers.PBKDF2PasswordHasher',
'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher',
'django.contrib.auth.hashers.BCryptPasswordHasher',
)
# ------ CORS-HEADERS SETTINGS ------ #
CORS_ORIGIN_ALLOW_ALL = True
# ------ SOCIAL AUTH SETTINGS ------ #
if 'social.apps.django_app.default' in INSTALLED_APPS:
MIDDLEWARE_CLASSES += ('social.apps.django_app.middleware.SocialAuthExceptionMiddleware',)
SOUTH_MIGRATION_MODULES = {
'default': 'social.apps.django_app.default.south_migrations'
}
# In Django 1.6, the default session serliazer has been switched to one based on JSON,
# rather than pickles, to improve security. Django-openid-auth does not support this
# because it attemps to store content that is not JSON serializable in sessions.
# See https://docs.djangoproject.com/en/dev/releases/1.6/#default-session-serialization-switched-to-json
# for details on the Django 1.6 change.
SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer'
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
'nodeshot.community.profiles.backends.EmailBackend',
'social.backends.facebook.FacebookAppOAuth2',
'social.backends.facebook.FacebookOAuth2',
'social.backends.github.GithubOAuth2',
'social.backends.google.GoogleOAuth',
'social.backends.google.GoogleOAuth2',
)
SOCIAL_AUTH_PIPELINE = (
'social.pipeline.social_auth.social_details',
'social.pipeline.social_auth.social_uid',
'social.pipeline.social_auth.auth_allowed',
'social.pipeline.social_auth.social_user',
'social.pipeline.user.get_username',
'social.pipeline.social_auth.associate_by_email',
'nodeshot.community.profiles.social_auth_extra.pipeline.create_user',
'social.pipeline.social_auth.associate_user',
'nodeshot.community.profiles.social_auth_extra.pipeline.load_extra_data',
'social.pipeline.user.user_details',
)
# register a new app:
SOCIAL_AUTH_FACEBOOK_KEY = '' # put your app id
SOCIAL_AUTH_FACEBOOK_SECRET = ''
SOCIAL_AUTH_FACEBOOK_SCOPE = ['email', 'user_about_me', 'user_birthday', 'user_hometown']
SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = ''
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = ''
# register a new app:
SOCIAL_AUTH_GITHUB_KEY = ''
SOCIAL_AUTH_GITHUB_SECRET = ''
SOCIAL_AUTH_GITHUB_SCOPE = ['user:email']
SOCIAL_AUTH_URL_NAMESPACE = 'social'
SOCIAL_AUTH_USER_MODEL = AUTH_USER_MODEL
SOCIAL_AUTH_DEFAULT_USERNAME = 'new_social_auth_user'
SOCIAL_AUTH_UUID_LENGTH = 3
SOCIAL_AUTH_SESSION_EXPIRATION = False
SOCIAL_AUTH_ASSOCIATE_BY_MAIL = True
SOCIAL_AUTH_PROTECTED_USER_FIELDS = ['email']
SOCIAL_AUTH_FORCE_EMAIL_VALIDATION = True
SOCIAL_AUTH_LOGIN_URL = '/'
SOCIAL_AUTH_LOGIN_REDIRECT_URL = '/'
SOCIAL_AUTH_LOGIN_ERROR_URL = '/'
# ------ DJANGO-LEAFLET SETTINGS ------ #
LEAFLET_CONFIG = {
'DEFAULT_CENTER': (49.06775, 30.62011),
'DEFAULT_ZOOM': 4,
'MIN_ZOOM': 1,
'MAX_ZOOM': 18,
'TILES': [
('Map', 'http://otile1.mqcdn.com/tiles/1.0.0/map/{z}/{x}/{y}.png', '© <a href="http://www.openstreetmap.org/copyright" target="_blank">OpenStreetMap</a> contributors | Tiles Courtesy of <a href="http://www.mapquest.com/" target="_blank">MapQuest</a>'),
('Satellite', 'http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', 'Source: <a href="http://www.esri.com/">Esri</a> © and the GIS User Community ')
],
'ATTRIBUTION_PREFIX': '<a href="http://github.com/ninuxorg/nodeshot" target="_blank">Nodeshot</a>',
'RESET_VIEW': False,
}
# ------ DJANGO-ROSETTA SETTINGS ------ #
ROSETTA_CACHE_NAME = 'rosetta'
ROSETTA_MESSAGES_PER_PAGE = 50
ROSETTA_EXCLUDED_APPLICATIONS = [app for app in INSTALLED_APPS if not app.startswith('nodeshot')]