forked from TabbycatDebate/tabbycat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.py
302 lines (260 loc) · 8.35 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
import sys
import os
import urllib.parse
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
MEDIA_ROOT = (os.path.join(BASE_DIR, 'media'), )
# ========================
# = Overwritten in Local =
# ========================
ADMINS = ('Philip and Chuan-Zheng', '[email protected]'),
MANAGERS = ADMINS
DEBUG = False
DEBUG_ASSETS = DEBUG
LIVE_RELOAD = False
# ===================
# = Global Settings =
# ===================
MEDIA_URL = '/media/'
TIME_ZONE = 'Australia/Melbourne'
LANGUAGE_CODE = 'en-us'
USE_I18N = True
TEST_RUNNER = 'django.test.runner.DiscoverRunner'
TABBYCAT_VERSION = '0.8.2'
TABBYCAT_CODENAME = 'Bengal'
READTHEDOCS_VERSION = 'v0.8.2'
# ===========================
# = Django-specific Modules =
# ===========================
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'utils.middleware.DebateMiddleware',
'django.contrib.messages.middleware.MessageMiddleware', )
TABBYCAT_APPS = ('actionlog',
'adjallocation',
'adjfeedback',
'availability',
'breakqual',
'draw',
'motions',
'options',
'participants',
'results',
'tournaments',
'venues',
'utils',
'standings',
'importer', )
INSTALLED_APPS = (
'jet',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.staticfiles',
'django.contrib.humanize',
'django.contrib.messages') \
+ TABBYCAT_APPS + (
'dynamic_preferences',
'django_extensions', # For Secret Generation Command
'compressor', )
ROOT_URLCONF = 'urls'
LOGIN_REDIRECT_URL = '/'
# =============
# = Templates =
# =============
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'OPTIONS': {
'context_processors': [
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'django.template.context_processors.debug',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.template.context_processors.request', # For Jet
'utils.context_processors.debate_context', # For tournament config vars
'utils.context_processors.get_menu_highlight', # For nav highlight
],
'loaders': [
('django.template.loaders.cached.Loader', [
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
]),
]
}
}
]
# ===========
# = Caching =
# ===========
PUBLIC_PAGE_CACHE_TIMEOUT = int(os.environ.get('PUBLIC_PAGE_CACHE_TIMEOUT', 60
* 1))
TAB_PAGES_CACHE_TIMEOUT = int(os.environ.get('TAB_PAGES_CACHE_TIMEOUT', 60 *
120))
# Default non-heroku cache is to use local memory
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
'LOCATION': 'unique-snowflake'
}
}
# Use the cache for sessions rather than the db
SESSION_ENGINE = 'django.contrib.sessions.backends.cached_db'
# ================
# = Static Files =
# ================
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'
STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'), )
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'compressor.finders.CompressorFinder', )
# Whitenoise
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage' # Gzipping and unique names
# =============
# = Pipelines =
# =============
# Compression
COMPRESS_ENABLED = True
COMPRESS_OFFLINE = True
COMPRESS_PRECOMPILERS = (('text/x-scss', 'django_libsass.SassCompiler'), )
LIBSASS_OUTPUT_STYLE = 'compressed'
# ===========
# = Logging =
# ===========
if os.environ.get('SENDGRID_USERNAME', ''):
SERVER_EMAIL = os.environ['SENDGRID_USERNAME']
DEFAULT_FROM_EMAIL = os.environ['SENDGRID_USERNAME']
EMAIL_HOST = 'smtp.sendgrid.net'
EMAIL_HOST_USER = os.environ['SENDGRID_USERNAME']
EMAIL_HOST_PASSWORD = os.environ['SENDGRID_PASSWORD']
EMAIL_PORT = 587
EMAIL_USE_TLS = True
if os.environ.get('DEBUG', ''):
DEBUG = bool(int(os.environ['DEBUG']))
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
# Only send emails to admins when debug is false
'()': 'django.utils.log.RequireDebugFalse',
}
},
'handlers': {
'console': {
'class': 'logging.StreamHandler',
'formatter': 'standard',
},
'mail_admins': {
# Any log item marked ERROR or higher will be sent to admins
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
}
},
'loggers': {
'django': {
'handlers': ['console'],
'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'),
},
'django.request': {
# Pass all ERRORS to mail_admins handler
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
},
'formatters': {
'standard': {
'format': '[%(asctime)s] %(levelname)s %(name)s: %(message)s',
'datefmt': '%d/%b/%Y %H:%M:%S'
},
},
}
for app in TABBYCAT_APPS:
LOGGING['loggers'][app] = {
'handlers': ['console'],
'level': os.getenv('DJANGO_LOG_LEVEL', 'DEBUG' if DEBUG else 'INFO'),
}
# ============
# = Messages =
# ============
from django.contrib.messages import constants as messages
MESSAGE_TAGS = {messages.ERROR: 'danger', }
# ==========
# = Heroku =
# ==========
SECRET_KEY = os.environ.get(
'DJANGO_SECRET_KEY', '#2q43u&tp4((4&m3i8v%w-6z6pp7m(v0-6@w@i!j5n)n15epwc')
# Parse database configuration from $DATABASE_URL
try:
import dj_database_url
DATABASES = {
'default': dj_database_url.config(default='postgres://localhost')
}
except:
pass
# Honor the 'X-Forwarded-Proto' header for request.is_secure()
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
# Allow all host headers
ALLOWED_HOSTS = ['*']
if os.environ.get('MEMCACHIER_SERVERS', ''):
try:
os.environ['MEMCACHE_SERVERS'] = os.environ[
'MEMCACHIER_SERVERS'].replace(',', ';')
os.environ['MEMCACHE_USERNAME'] = os.environ['MEMCACHIER_USERNAME']
os.environ['MEMCACHE_PASSWORD'] = os.environ['MEMCACHIER_PASSWORD']
CACHES = {
'default': {
'BACKEND': 'django_pylibmc.memcached.PyLibMCCache',
'TIMEOUT': 36000,
'BINARY': True,
'OPTIONS': { # Maps to pylibmc "behaviors"
# Enable faster IO
'no_block': True,
'tcp_nodelay': True,
},
# Timeout for set/get requests
'_poll_timeout': 2000,
}
}
except:
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'
}
}
if os.environ.get('DEBUG', ''):
DEBUG = bool(int(os.environ['DEBUG']))
TEMPLATES[0]['OPTIONS']['debug'] = True
# =============
# = Travis CI =
# =============
if os.environ.get('TRAVIS', '') == 'true':
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'USER': 'postgres',
'PASSWORD': '',
'HOST': 'localhost',
'PORT': '',
}
}
# ===================
# = Local Overrides =
# ===================
try:
LOCAL_SETTINGS
except NameError:
try:
from local_settings import *
except ImportError:
pass