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