f387ca41fe9e0f12e13ef265f47698f6b23da290
[oweals/karmaworld.git] / karmaworld / settings / common.py
1 #!/usr/bin/env python
2 # -*- coding:utf8 -*-
3 # Copyright (C) 2012  FinalsClub Foundation
4 """ Common settings and globals. """
5 from datetime import timedelta
6 import sys
7 from os.path import abspath, basename, dirname, join, normpath
8 from sys import path
9 from djcelery import setup_loader
10 import dj_database_url
11 from karmaworld.secret.filepicker import FILEPICKER_API_KEY as fp_api
12
13 FILEPICKER_API_KEY = fp_api
14 FILEPICKER_INPUT_TYPE = 'filepicker'
15
16 from karmaworld.secret.static_s3 import *
17
18 SERIALIZATION_MODULES = {'json-pretty': 'karmaworld.apps.serializers.json_pretty'}
19
20
21 ########## REQUIRED SECURITY CONFIGURATION
22 # See: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-ALLOWED_HOSTS
23 # The hosts that this server runs from.
24 ALLOWED_HOSTS = [
25     '127.0.0.1', # for dev systems / VMs, but should be safe enough
26     'localhost', # for dev systems / VMs, but should be safe enough
27     'beta.karmanotes.org',
28     'www.karmanotes.org',
29     'karmanotes.org',
30     'quiz.karmanotes.org',
31 ]
32 ########## END SECURITY CONFIGURATION
33
34 ########## PATH CONFIGURATION
35 # Absolute filesystem path to the Django project directory:
36 DJANGO_ROOT = dirname(dirname(abspath(__file__)))
37
38 # Absolute filesystem path to the top-level project folder:
39 SITE_ROOT = dirname(DJANGO_ROOT)
40
41 # Site name:
42 SITE_NAME = basename(DJANGO_ROOT)
43
44 # Add our project to our pythonpath, this way we don't need to type our project
45 # name in our dotted import paths:
46 path.append(DJANGO_ROOT)
47 ########## END PATH CONFIGURATION
48
49
50 ########## DEBUG CONFIGURATION
51 # See: https://docs.djangoproject.com/en/dev/ref/settings/#debug
52 DEBUG = False
53
54 # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-debug
55 TEMPLATE_DEBUG = DEBUG
56 ########## END DEBUG CONFIGURATION
57
58
59 ########## MANAGER CONFIGURATION
60 # See: https://docs.djangoproject.com/en/dev/ref/settings/#admins
61 ADMINS = (
62     ('Seth Woodworth', 'seth@finalsclub.org'),
63     ('Charles Holbrow', 'charles@finalsclub.org'),
64     ('Andrew Magliozzi', 'andrew@finalsclub.org'),
65 )
66
67 # See: https://docs.djangoproject.com/en/dev/ref/settings/#managers
68 MANAGERS = ADMINS
69 ########## END MANAGER CONFIGURATION
70
71
72 ########## DATABASE CONFIGURATION
73 # See: https://docs.djangoproject.com/en/dev/ref/settings/#databases
74 DATABASES = {'default': dj_database_url.config()}
75 ########## END DATABASE CONFIGURATION
76
77
78 ########## GENERAL CONFIGURATION
79 # See: https://docs.djangoproject.com/en/dev/ref/settings/#time-zone
80 TIME_ZONE = 'America/New_York'
81
82 # See: https://docs.djangoproject.com/en/dev/ref/settings/#language-code
83 LANGUAGE_CODE = 'en-us'
84
85 # See: https://docs.djangoproject.com/en/dev/ref/settings/#site-id
86 SITE_ID = 1
87
88 # See: https://docs.djangoproject.com/en/dev/ref/settings/#use-i18n
89 USE_I18N = True
90
91 # See: https://docs.djangoproject.com/en/dev/ref/settings/#use-l10n
92 USE_L10N = True
93 ########## END GENERAL CONFIGURATION
94
95
96 ########## MEDIA CONFIGURATION
97 # See: https://docs.djangoproject.com/en/dev/ref/settings/#media-root
98 MEDIA_ROOT = normpath(join(DJANGO_ROOT, 'media'))
99
100 # See: https://docs.djangoproject.com/en/dev/ref/settings/#media-url
101 MEDIA_URL = '/media/'
102 ########## END MEDIA CONFIGURATION
103
104
105 ########## STATIC FILE CONFIGURATION
106
107 # See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#std:setting-STATICFILES_DIRS
108 STATICFILES_DIRS = (
109     normpath(join(DJANGO_ROOT, 'assets')),
110 )
111
112 # See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#staticfiles-finders
113 STATICFILES_FINDERS = (
114     'django.contrib.staticfiles.finders.FileSystemFinder',
115     'django.contrib.staticfiles.finders.AppDirectoriesFinder',
116     'compressor.finders.CompressorFinder',
117 )
118 ########## END STATIC FILE CONFIGURATION
119
120
121 ########## SECRET CONFIGURATION
122 # See: https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
123 SECRET_KEY = r"(s1k!&^7l28k&nrm2ek(qqo&19%y(zn#=^zq_*ur2@irjun0x4"
124 ########## END SECRET CONFIGURATION
125
126
127 ########## FIXTURE CONFIGURATION
128 # See: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-FIXTURE_DIRS
129 FIXTURE_DIRS = (
130     normpath(join(DJANGO_ROOT, 'fixtures')),
131 )
132 ########## END FIXTURE CONFIGURATION
133
134
135 ########## TEMPLATE CONFIGURATION
136 # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-context-processors
137 TEMPLATE_CONTEXT_PROCESSORS = (
138     'django.contrib.auth.context_processors.auth',
139     'django.core.context_processors.debug',
140     'django.core.context_processors.i18n',
141     'django.core.context_processors.media',
142     'django.core.context_processors.static',
143     'django.core.context_processors.tz',
144     'django.contrib.messages.context_processors.messages',
145     'django.core.context_processors.request',
146     'karmaworld.apps.notes.context_processors.s3_url',
147
148     # allauth specific context processors
149     "allauth.account.context_processors.account",
150     "allauth.socialaccount.context_processors.socialaccount",
151 )
152
153 # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-loaders
154 TEMPLATE_LOADERS = (
155     'django.template.loaders.filesystem.Loader',
156     'django.template.loaders.app_directories.Loader',
157 )
158
159 # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-dirs
160 TEMPLATE_DIRS = (
161     normpath(join(DJANGO_ROOT, 'templates')),
162 )
163 ########## END TEMPLATE CONFIGURATION
164
165
166 ########## MIDDLEWARE CONFIGURATION
167 # See: https://docs.djangoproject.com/en/dev/ref/settings/#middleware-classes
168 MIDDLEWARE_CLASSES = (
169     # Use GZip compression to reduce bandwidth.
170     'django.middleware.gzip.GZipMiddleware',
171
172     # Version control middleware.
173     'reversion.middleware.RevisionMiddleware',
174
175     # Default Django middleware.
176     'django.middleware.common.CommonMiddleware',
177     'django.contrib.sessions.middleware.SessionMiddleware',
178     'django.middleware.csrf.CsrfViewMiddleware',
179     'django.contrib.auth.middleware.AuthenticationMiddleware',
180     'django.contrib.messages.middleware.MessageMiddleware',
181 )
182 ########## END MIDDLEWARE CONFIGURATION
183
184
185 ########## URL CONFIGURATION
186 # See: https://docs.djangoproject.com/en/dev/ref/settings/#root-urlconf
187 ROOT_URLCONF = '%s.urls' % SITE_NAME
188 ########## END URL CONFIGURATION
189
190
191 ########## APP CONFIGURATION
192 DJANGO_APPS = (
193     # Default Django apps:
194     'django.contrib.auth',
195     'django.contrib.contenttypes',
196     'django.contrib.sessions',
197     'django.contrib.sites',
198     'django.contrib.messages',
199     'django.contrib.staticfiles',
200
201     # Useful template tags:
202     'django.contrib.humanize',
203
204     # grappelli django-admin improvment, must be added before admin
205     'grappelli',
206
207     # Admin panel and documentation:
208     'django.contrib.admin',
209     'django.contrib.admindocs',
210 )
211
212 THIRD_PARTY_APPS = (
213     # Database migration helpers:
214     'south',
215
216     # Static file management:
217     'compressor',
218
219     # Asynchronous task queue:
220     'djcelery',
221
222     # Tagging https://github.com/yedpodtrzitko/django-taggit
223     'taggit',
224
225     # Version control
226     'reversion',
227
228     # AJAX endpoints for autocompletion
229     'ajax_select',
230     'ajax_select_cascade',
231
232     'allauth',
233     'allauth.account',
234     'allauth.socialaccount',
235     # ... include the providers you want to enable:
236     'allauth.socialaccount.providers.facebook',
237     'allauth.socialaccount.providers.google',
238     'allauth.socialaccount.providers.twitter',
239
240     # Added to make quizzes moderation nicer
241     'nested_inlines',
242 )
243
244 LOCAL_APPS = (
245     # file handling app
246     'karmaworld.apps.notes',
247     'karmaworld.apps.courses',
248     'karmaworld.apps.document_upload',
249     'karmaworld.apps.users',
250     'karmaworld.apps.moderation',
251     'karmaworld.apps.licenses',
252     'karmaworld.apps.quizzes',
253 )
254
255 # See: https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps
256 INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS
257 ########## END APP CONFIGURATION
258
259
260 ########## AUTHENTICATION
261
262 AUTHENTICATION_BACKENDS = (
263     # Needed to login by username in Django admin, regardless of `allauth`
264     "django.contrib.auth.backends.ModelBackend",
265
266     # `allauth` specific authentication methods, such as login by e-mail
267     "allauth.account.auth_backends.AuthenticationBackend",
268 )
269
270 ACCOUNT_EMAIL_REQUIRED = True
271 ACCOUNT_AUTHENTICATION_METHOD = "email"
272 ACCOUNT_CONFIRM_EMAIL_ON_GET = False
273 ACCOUNT_EMAIL_VERIFICATION = "optional"
274 ACCOUNT_EMAIL_SUBJECT_PREFIX = "KarmaNotes.org -- "
275 ACCOUNT_USERNAME_REQUIRED = True
276 SOCIALACCOUNT_EMAIL_REQUIRED = True
277 SOCIALACCOUNT_EMAIL_VERIFICATION = "optional"
278 SOCIALACCOUNT_QUERY_EMAIL = True
279 SOCIALACCOUNT_AUTO_SIGNUP = False
280 ACCOUNT_USER_DISPLAY = 'karmaworld.apps.users.models.user_display_name'
281 ACCOUNT_SIGNUP_FORM_CLASS = 'karmaworld.apps.users.forms.SignupForm'
282 ACCOUNT_DEFAULT_HTTP_PROTOCOL = 'https'
283 LOGIN_REDIRECT_URL = '/'
284
285 AUTH_PROFILE_MODULE = 'users.UserProfile'
286
287 ######### END AUTHENTICATION
288
289 ########## LOGGING CONFIGURATION
290 # See: https://docs.djangoproject.com/en/dev/ref/settings/#logging
291 LOGGING = {
292     'version': 1,
293     'disable_existing_loggers': False,
294     'filters': {
295          'require_debug_false': {
296              '()': 'django.utils.log.RequireDebugFalse'
297          }
298      },
299     'handlers': {
300         'console': {
301             'level': 'INFO',
302             'class': 'logging.StreamHandler'
303         },
304         'mail_admins': {
305             'level': 'ERROR',
306             'filters': ['require_debug_false'],
307             'class': 'django.utils.log.AdminEmailHandler'
308         }
309     },
310     'loggers': {
311         'django': {
312             'handlers': ['console'],
313             'level': 'INFO'
314         },
315         'django.request': {
316             'handlers': ['mail_admins'],
317             'level': 'ERROR',
318             'propagate': True
319         },
320     }
321 }
322 ########## END LOGGING CONFIGURATION
323
324
325 ########## CELERY CONFIGURATION
326 # See: http://celery.readthedocs.org/en/latest/configuration.html#celery-task-result-expires
327 CELERY_TASK_RESULT_EXPIRES = timedelta(minutes=30)
328
329 # See: http://celery.github.com/celery/django/
330 setup_loader()
331 ########## END CELERY CONFIGURATION
332
333
334 ########## WSGI CONFIGURATION
335 # See: https://docs.djangoproject.com/en/dev/ref/settings/#wsgi-application
336 WSGI_APPLICATION = 'wsgi.application'
337 ########## END WSGI CONFIGURATION
338
339
340 ########## COMPRESSION CONFIGURATION
341 # See: http://django_compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_ENABLED
342 COMPRESS_ENABLED = True
343
344 # See: http://django_compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_CSS_FILTERS
345 COMPRESS_CSS_FILTERS = [
346     'compressor.filters.template.TemplateFilter',
347 ]
348
349 # See: http://django_compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_JS_FILTERS
350 COMPRESS_JS_FILTERS = [
351     'compressor.filters.template.TemplateFilter',
352 ]
353 ########## END COMPRESSION CONFIGURATION
354
355 ########## SESSION CONFIGURATION
356
357 SESSION_ENGINE = 'django.contrib.sessions.backends.db'
358 SESSION_COOKIE_AGE = 63072000    # 2 years in seconds
359
360 ########## END SESSION CONFIGURATION
361
362 ########## TAGGIT CONFIGURATION
363 # From https://github.com/yedpodtrzitko/django-taggit
364
365 # Use lowercase tags
366 TAGGIT_FORCE_LOWERCASE = True
367
368 # Ignore common stopwords
369 TAGGIT_STOPWORDS = [u'a', u'an', u'and', u'be', u'from', u'of']
370
371 ########## END TAGGIT CONFIGURATION
372
373
374 ########## HONEYPOT CONFIGURATION
375 # parts of this code borrow from
376 # https://github.com/sunlightlabs/django-honeypot
377 HONEYPOT_FIELD_NAME = "instruction_url" # see that "_url"? bots gotta want that.
378 HONEYPOT_VALUE = ""
379 HONEYPOT_LABEL = "Humans, leave this blank so we can prevent robots from submitting bogus courses"
380 HONEYPOT_ERROR = "You did not follow directions."
381 ########## END HONEYPOT CONFIGURATION
382
383
384 ########## SOUTH CONFIGURATION
385 SOUTH_MIGRATION_MODULES = {
386     'taggit': 'taggit.south_migrations',
387 }
388 ########## END SOUTH CONFIGURATION
389
390 ########## AJAX SELECTS CONFIGURATION
391 AJAX_SELECT_BOOTSTRAP = False
392 ########## END AJAX SELECTS CONFIGURATION
393
394
395 ########## TESTING CONFIGURATION
396 TESTING = 'test' in sys.argv
397 ########## END TESTING CONFIGURATION