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