-
Notifications
You must be signed in to change notification settings - Fork 151
Expand file tree
/
Copy pathsettings.py
More file actions
447 lines (369 loc) · 14.9 KB
/
settings.py
File metadata and controls
447 lines (369 loc) · 14.9 KB
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
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
# Django settings for project project.
import datetime
import os
import os.path
from django.core.exceptions import ImproperlyConfigured
HERE = os.path.dirname(__file__)
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
# ('Your Name', 'your_email@example.com'),
)
MANAGERS = ADMINS
USE_GEODB = (os.environ.get('USE_GEODB', 'True').lower() == 'true')
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.dummy',
}
}
ALLOWED_HOSTS = ['*']
# How long to keep api cache values. Since the api will invalidate the cache
# automatically when appropriate, this can (and should) be set to something
# large.
API_CACHE_TIMEOUT = 3600 # an hour
REST_FRAMEWORK = {
'PAGINATE_BY': 100,
'PAGINATE_BY_PARAM': 'page_size'
}
# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# On Unix systems, a value of None will cause Django to use the same
# timezone as the operating system.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = 'America/Chicago'
# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'
SITE_ID = 1
# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True
# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale.
USE_L10N = True
# If you set this to False, Django will not use timezone-aware datetimes.
USE_TZ = True
# Path or URL prefix for all app paths and static files. This is useful if you
# want to run Shareabouts under a subpath, such as `/subpath/`. Note that if the
# `BASE_URL` is set, the site will not work directly through runserver, so you
# should use a reverse proxy in front of it. Thus by default, this is an empty
# string.
BASE_URL = os.environ.get('BASE_URL', '')
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
MEDIA_ROOT = ''
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
MEDIA_URL = ''
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
from os.path import dirname, abspath, join as pathjoin
STATIC_ROOT=abspath(pathjoin(dirname(__file__), '..', '..', 'staticfiles'))
COMPRESS_ROOT = STATIC_ROOT
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = BASE_URL + '/static/'
COMPRESS_URL = STATIC_URL
# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
# Cache-busting static assets
STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.ManifestStaticFilesStorage'
ATTACHMENT_STORAGE = 'django.core.files.storage.FileSystemStorage'
# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
'compressor.finders.CompressorFinder',
)
# Make this unique, and don't share it with anybody.
SECRET_KEY = 'pbv(g=%7$$4rzvl88e24etn57-%n0uw-@y*=7ak422_3!zrc9+'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'OPTIONS': {
'loaders': (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
),
'context_processors': (
"django.template.context_processors.debug",
"django.template.context_processors.i18n",
"django.template.context_processors.media",
"django.template.context_processors.request",
"django.template.context_processors.static",
"django.template.context_processors.tz",
"django.contrib.messages.context_processors.messages",
"django.contrib.auth.context_processors.auth",
"project.context_processors.settings_context",
)
}
},
]
MIDDLEWARE = (
'sa_web.middleware.CacheRequestBody',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
# Uncomment the next line for simple clickjacking protection:
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
SESSION_ENGINE = 'django.contrib.sessions.backends.signed_cookies'
SESSION_COOKIE_NAME = 'sa-web-session'
ROOT_URLCONF = 'project.urls'
# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'project.wsgi.application'
TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
# 3rd-party reusaple apps
'jstemplate',
'compressor',
'django_extensions',
# Project apps
'sa_web',
'sa_login',
'sa_admin',
'proxy',
)
# Use a test runner that does not use a database.
TEST_RUNNER = 'sa_web.test_runner.DatabaselessTestSuiteRunner'
# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
# the site admins on every HTTP 500 error when DEBUG=False.
# 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': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'handlers': {
'console': {
'level': 'DEBUG' if DEBUG else 'INFO',
'class': 'logging.StreamHandler',
},
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
}
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
'sa_web': {
'handlers': ['console'],
'level': 'DEBUG',
'propagate': True,
},
},
'root': {
'handlers': ['console'],
'level': 'INFO',
},
}
##############################################################################
# Environment overrides
# ---------------------
# Pull in certain values from the environment.
env = os.environ
if 'DEBUG' in env:
DEBUG = TEMPLATE_DEBUG = (env.get('DEBUG').lower() in ('true', 'on', 't', 'yes'))
if 'DATABASE_URL' in env:
import dj_database_url
# NOTE: Be sure that your DATABASE_URL has the 'postgis://' scheme.
DATABASES = {'default': dj_database_url.config()}
if USE_GEODB:
DATABASES['default']['ENGINE'] = 'django.contrib.gis.db.backends.postgis'
if 'REDIS_URL' in env:
CACHES = {
'default': {
'BACKEND': 'django_redis.cache.RedisCache',
'LOCATION': env.get('REDIS_URL'),
}
}
# Django sessions
SESSION_ENGINE = 'django.contrib.sessions.backends.cache'
SHAREABOUTS = {}
if 'SHAREABOUTS_FLAVOR' in env:
SHAREABOUTS['FLAVOR'] = env.get('SHAREABOUTS_FLAVOR')
if 'SHAREABOUTS_DATASET_ROOT' in env:
SHAREABOUTS['DATASET_ROOT'] = env.get('SHAREABOUTS_DATASET_ROOT')
if 'SHAREABOUTS_DATASET_KEY' in env:
SHAREABOUTS['DATASET_KEY'] = env.get('SHAREABOUTS_DATASET_KEY')
if all([key in env for key in ('SHAREABOUTS_AWS_KEY',
'SHAREABOUTS_AWS_SECRET',
'SHAREABOUTS_AWS_BUCKET')]):
AWS_ACCESS_KEY_ID = env['SHAREABOUTS_AWS_KEY']
AWS_SECRET_ACCESS_KEY = env['SHAREABOUTS_AWS_SECRET']
AWS_STORAGE_BUCKET_NAME = env['SHAREABOUTS_AWS_BUCKET']
AWS_QUERYSTRING_AUTH = False
AWS_PRELOAD_METADATA = True
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
ATTACHMENT_STORAGE = DEFAULT_FILE_STORAGE
STATICFILES_STORAGE = DEFAULT_FILE_STORAGE
STATIC_URL = 'https://%s.s3.amazonaws.com/' % AWS_STORAGE_BUCKET_NAME
if 'SHAREABOUTS_TWITTER_KEY' in env \
and 'SHAREABOUTS_TWITTER_SECRET' in env:
SOCIAL_AUTH_TWITTER_KEY = env['SHAREABOUTS_TWITTER_KEY']
SOCIAL_AUTH_TWITTER_SECRET = env['SHAREABOUTS_TWITTER_SECRET']
if 'SHAREABOUTS_FACEBOOK_KEY' in env \
and 'SHAREABOUTS_FACEBOOK_SECRET' in env:
SOCIAL_AUTH_FACEBOOK_KEY = env['SHAREABOUTS_FACEBOOK_KEY']
SOCIAL_AUTH_FACEBOOK_SECRET = env['SHAREABOUTS_FACEBOOK_SECRET']
if 'EMAIL_ADDRESS' in env:
EMAIL_ADDRESS = env['EMAIL_ADDRESS']
if 'EMAIL_HOST' in env:
EMAIL_HOST = env['EMAIL_HOST']
if 'EMAIL_PORT' in env:
EMAIL_PORT = env['EMAIL_PORT']
if 'EMAIL_USERNAME' in env:
EMAIL_HOST_USER = env['EMAIL_USERNAME']
if 'EMAIL_PASSWORD' in env:
EMAIL_HOST_PASSWORD = env['EMAIL_PASSWORD']
if 'EMAIL_USE_TLS' in env:
EMAIL_USE_TLS = env['EMAIL_USE_TLS']
if 'EMAIL_BACKEND' in env:
EMAIL_BACKEND = env['EMAIL_BACKEND']
if 'EMAIL_NOTIFICATIONS_BCC' in env:
EMAIL_NOTIFICATIONS_BCC = env['EMAIL_NOTIFICATIONS_BCC'].split(',')
if all(['S3_MEDIA_BUCKET' in env, 'AWS_ACCESS_KEY' in env, 'AWS_SECRET_KEY' in env]):
AWS_STORAGE_BUCKET_NAME = env.get('S3_MEDIA_BUCKET')
AWS_ACCESS_KEY_ID = env.get('AWS_ACCESS_KEY')
AWS_SECRET_ACCESS_KEY = env.get('AWS_SECRET_KEY')
# Set the compress storage, but not the static files storage, to S3.
COMPRESS_ENABLED = env.get('COMPRESS_ENABLED', str(not DEBUG)).lower() in ('true', 't')
COMPRESS_STORAGE = 'project.backends.S3BotoStorage'
COMPRESS_URL = '//%s.s3.amazonaws.com/' % AWS_STORAGE_BUCKET_NAME
# For sitemaps and caching -- will be a new value every time the server starts
LAST_DEPLOY_DATE = datetime.datetime.now().replace(second=0, microsecond=0).isoformat()
if 'GOOGLE_ANALYTICS_ID' in env:
GOOGLE_ANALYTICS_ID = env.get('GOOGLE_ANALYTICS_ID')
if 'GOOGLE_ANALYTICS_DOMAIN' in env:
GOOGLE_ANALYTICS_DOMAIN = env.get('GOOGLE_ANALYTICS_DOMAIN')
MAPQUEST_KEY = env.get('MAPQUEST_KEY', '')
MAPBOX_TOKEN = env.get('MAPBOX_TOKEN', '')
# Error logging
import raven
import re
RAVEN_CONFIG = {
'dsn': os.environ.get('SENTRY_DSN'),
'public_dsn': re.sub(':[^/@]+', '', os.environ.get('SENTRY_DSN', '')),
}
##############################################################################
# Local settings overrides
# ------------------------
# Override settings values by importing the local_settings.py module.
LOCAL_SETTINGS_FILE = os.path.join(os.path.dirname(__file__), 'local_settings.py')
if os.path.exists(LOCAL_SETTINGS_FILE):
# By doing this instead of import, local_settings.py can refer to
# local variables from settings.py without circular imports.
with open(LOCAL_SETTINGS_FILE) as settingsfile:
exec(settingsfile.read())
try:
if not isinstance(EMAIL_NOTIFICATIONS_BCC, (list, tuple)):
raise ImproperlyConfigured('EMAIL_NOTIFICATIONS_BCC must be a list or tuple')
except NameError:
pass
##############################################################################
# Flavor defaults
# ---------------
# By default, the flavor is assumed to be a local python package. If no
# CONFIG_FILE or PACKAGE is specified, they are constructed as below.
try:
SHAREABOUTS
flavor = SHAREABOUTS['FLAVOR']
except (NameError, TypeError, KeyError):
raise ImproperlyConfigured('No SHAREABOUTS configuration defined. '
'Did you forget to copy the local settings template?')
here = os.path.abspath(os.path.dirname(__file__))
if 'CONFIG' not in SHAREABOUTS:
SHAREABOUTS['CONFIG'] = os.path.abspath(os.path.join(here, '..', 'flavors', flavor))
if 'PACKAGE' not in SHAREABOUTS:
SHAREABOUTS['PACKAGE'] = '.'.join(['flavors', flavor])
INSTALLED_APPS = (SHAREABOUTS['PACKAGE'],) + INSTALLED_APPS
##############################################################################
# Locale paths
# ------------
# Help Django find any translation files.
LOCALE_PATHS = (
os.path.join(HERE, '..', 'conf', 'locale'),
os.path.join(HERE, '..', 'sa_web', 'locale'),
os.path.join(HERE, '..', 'flavors', flavor, 'locale'),
)
if 'DATASET_ROOT' in SHAREABOUTS and SHAREABOUTS['DATASET_ROOT'].startswith('/'):
INSTALLED_APPS += (
# =================================
# 3rd-party reusaple apps
# =================================
'rest_framework',
'storages',
'social.apps.django_app.default',
'raven.contrib.django.raven_compat',
'django_ace',
'django_object_actions',
# OAuth
'provider',
'provider.oauth2',
'corsheaders',
# =================================
# Project apps
# =================================
'sa_api_v2',
'sa_api_v2.apikey',
'sa_api_v2.cors',
'remote_client_user',
)
###############################################################################
#
# Authentication
#
AUTHENTICATION_BACKENDS = (
# See http://django-social-auth.readthedocs.org/en/latest/configuration.html
# for list of available backends.
'social.backends.twitter.TwitterOAuth',
'social.backends.facebook.FacebookOAuth2',
'sa_api_v2.auth_backends.CachedModelBackend',
)
AUTH_USER_MODEL = 'sa_api_v2.User'
SOCIAL_AUTH_USER_MODEL = 'sa_api_v2.User'
SOCIAL_AUTH_PROTECTED_USER_FIELDS = ['email',]
SOCIAL_AUTH_FACEBOOK_EXTRA_DATA = ['name', 'picture', 'bio']
SOCIAL_AUTH_TWITTER_EXTRA_DATA = ['name', 'description', 'profile_image_url']
# Explicitly request the following extra things from facebook
SOCIAL_AUTH_FACEBOOK_PROFILE_EXTRA_PARAMS = {'fields': 'id,name,picture.width(96).height(96),first_name,last_name,bio'}
SOCIAL_AUTH_LOGIN_ERROR_URL = 'remote-social-login-error'