/
defaults.py
406 lines (315 loc) · 10.7 KB
/
defaults.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
import os
from django.contrib import messages
SETTINGS_DIR = os.path.dirname(__file__)
PROJECT_DIR = os.path.dirname(SETTINGS_DIR)
BUILDOUT_DIR = os.path.dirname(PROJECT_DIR)
VAR_DIR = os.path.join(BUILDOUT_DIR, "var")
##########################################################################
#
# Secret settings
#
##########################################################################
# If a secret_settings file isn't defined, open a new one and save a
# SECRET_KEY in it. Then import it. All passwords and other secret
# settings should be stored in secret_settings.py. NOT in settings.py
try:
from secret_settings import *
except ImportError:
print "Couldn't find secret_settings file. Creating a new one."
secret_settings_loc = os.path.join(SETTINGS_DIR, "secret_settings.py")
with open(secret_settings_loc, 'w') as secret_settings:
secret_key = ''.join([chr(ord(x) % 90 + 33) for x in os.urandom(40)])
secret_settings.write("SECRET_KEY = '''%s'''\n" % secret_key)
from secret_settings import *
##########################################################################
#
# Administrative settings
#
##########################################################################
ADMINS = (
# ('Your Name', 'your_email@example.com'),
)
MANAGERS = ADMINS
##########################################################################
#
# Authentication settings
#
##########################################################################
# When a user successfully logs in, redirect here by default
LOGIN_REDIRECT_URL = '/'
# Require that users who are signing up provide an email address
ACCOUNT_EMAIL_REQUIRED = True
# ACCOUNT_EMAIL_VERIFICATION is set in development.py and production.py
ACCOUNT_EMAIL_SUBJECT_PREFIX = "[SIG-Game]"
ACCOUNT_AUTHENTICATION_METHOD = "username_email"
# Try to pull username/email from provider.
SOCIALACCOUNT_AUTO_SIGNUP = True
SOCIALACCOUNT_PROVIDERS = {
'openid': {
'SERVERS': [
{'id': 'yahoo',
'name': 'Yahoo',
'openid_url': 'http://me.yahoo.com'},
{'id': 'google',
'name': 'Google',
'openid_url': 'https://www.google.com/accounts/o8/id'},
]
}
}
# Django Guardian settings
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend', # this is default
'allauth.account.auth_backends.AuthenticationBackend',
'guardian.backends.ObjectPermissionBackend',
)
ANONYMOUS_USER_ID = -1
ABSOLUTE_URL_OVERRIDES = {
'auth.user': lambda u: "/profile/%s/" % u.username,
}
##########################################################################
#
# API settings
#
##########################################################################
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAdminUser',
)
}
##########################################################################
#
# Bleach settings
#
##########################################################################
import bleach
ALLOWED_HTML_TAGS = bleach.ALLOWED_TAGS + ['h1', 'h2', 'h3', 'p', 'img']
ALLOWED_HTML_ATTRS = bleach.ALLOWED_ATTRIBUTES
ALLOWED_HTML_ATTRS.update({
'img': ['src', 'alt'],
})
##########################################################################
#
# Crispy settings
#
##########################################################################
CRISPY_TEMPLATE_PACK = 'bootstrap3'
##########################################################################
#
# Celery settings
#
##########################################################################
import djcelery
djcelery.setup_loader()
try:
BROKER_URL
except NameError:
BROKER_URL = 'django://'
CELERYBEAT_SCHEDULER = "djcelery.schedulers.DatabaseScheduler"
CELERY_TASK_SERIALIZER = 'pickle'
CELERY_ACCEPT_CONTENT = ['pickle']
##########################################################################
#
# Competition settings
#
##########################################################################
QR_DIR = os.path.join(VAR_DIR, "qr")
##########################################################################
#
# Greta settings
#
##########################################################################
GRETA_ROOT_DIR = os.path.join(VAR_DIR, "repos")
GRETA_ROOT_TEST_DIR = os.path.join(VAR_DIR, "test_repos")
GRETA_ARCHIVE_DIR = os.path.join(VAR_DIR, "archives")
GRETA_PAGE_COMMITS_BY = 10
##########################################################################
#
# Git settings
#
##########################################################################
# These settings should be included in secret_settings.py
# GIT_HOST = None
# GIT_PORT = None
GIT_PROTOCOL = 'ssh'
##########################################################################
#
# Testing settings
#
##########################################################################
# Sets the testrunner to Nose
TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
##########################################################################
#
# Blog settings
#
##########################################################################
##########################################################################
#
# Messages settings
#
##########################################################################
# Change the default messgae tags to play nice with Bootstrap
MESSAGE_TAGS = {
messages.DEBUG: 'alert-info',
messages.INFO: 'alert-info',
messages.SUCCESS: 'alert-success',
messages.WARNING: 'alert-warning',
messages.ERROR: 'alert-danger',
}
##########################################################################
#
# Connection settings
#
##########################################################################
ALLOWED_HOSTS = ["localhost", "megaminerai.com"]
##########################################################################
#
# Database settings
#
##########################################################################
# Should be overridden by development.py or production.py
DATABASES = None
# Make every HTTP request an atomic transaction
ATOMIC_REQUESTS = True
# Add project/fixtures to the list of places where django looks for
# fixtures to install.
FIXTURE_DIRS = (
os.path.join(PROJECT_DIR, "fixtures"),
)
##########################################################################
#
# Cache settings
#
##########################################################################
CACHE_MIDDLEWARE_SECONDS = 5
CACHE_MIDDLEWARE_KEY_PREFIX = 'web_cache'
##########################################################################
#
# Location settings
#
##########################################################################
TIME_ZONE = 'America/Chicago'
LANGUAGE_CODE = 'en-us'
USE_I18N = False
USE_L10N = True
##########################################################################
#
# Static files settings
#
##########################################################################
MEDIA_ROOT = os.path.join(VAR_DIR, "uploads")
MEDIA_URL = '/uploads/'
STATIC_ROOT = os.path.join(VAR_DIR, "static")
STATIC_URL = '/static/'
ADMIN_MEDIA_PREFIX = '/static/admin/'
STATICFILES_DIRS = (
os.path.join(PROJECT_DIR, "static"),
)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
##########################################################################
#
# Template settings
#
##########################################################################
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
'django.template.loaders.eggs.Loader',
)
TEMPLATE_DIRS = (
os.path.join(PROJECT_DIR, "templates"),
)
TEMPLATE_CONTEXT_PROCESSORS = (
'django.contrib.auth.context_processors.auth',
'django.core.context_processors.debug',
'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',
# for django-admin-tools
'django.core.context_processors.request',
'allauth.account.context_processors.account',
'allauth.socialaccount.context_processors.socialaccount',
)
##########################################################################
#
# Middleware settings
#
##########################################################################
MIDDLEWARE_CLASSES = (
'django.middleware.cache.UpdateCacheMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.cache.FetchFromCacheMiddleware',
)
##########################################################################
#
# URL settings
#
##########################################################################
ROOT_URLCONF = 'webserver.urls'
##########################################################################
#
# Installed apps settings
#
##########################################################################
INSTALLED_APPS = (
# Django AllAuth
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.openid',
# Django Admin Tools
'admin_tools',
'admin_tools.theming',
'admin_tools.menu',
'admin_tools.dashboard',
'django.contrib.auth',
'django.contrib.admin',
'django.contrib.admindocs',
'django.contrib.comments',
'django.contrib.contenttypes',
'django.contrib.messages',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.staticfiles',
'django.contrib.flatpages', # For serving docs and other flat pages
# django-crispy-forms
'crispy_forms',
# Competition app
'competition',
# Git app
'greta',
# API stuff
'rest_framework',
'webserver.home',
'webserver.profiles',
'webserver.codemanagement',
'webserver.hermes',
'webserver.badges',
'brabeion',
'gunicorn', # Adds gunicorn management commands
'guardian',
'djcelery', # Django celery
'kombu.transport.django',
'raven.contrib.django.raven_compat', # Sentry client
'django_extensions',
'django_nose',
'south'
)
##########################################################################
#
# Logging settings
#
##########################################################################
# Check development.py or production.py for specific logging settings.
LOGGING = None