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
10 from djcelery import setup_loader
11 import dj_database_url
13 FILEPICKER_API_KEY = os.environ['FILEPICKER_API_KEY']
14 FILEPICKER_INPUT_TYPE = 'filepicker'
16 SERIALIZATION_MODULES = {'json-pretty': 'karmaworld.apps.serializers.json_pretty'}
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.
25 ########## END SECURITY CONFIGURATION
27 ########## PATH CONFIGURATION
28 # Absolute filesystem path to the Django project directory:
29 DJANGO_ROOT = dirname(dirname(abspath(__file__)))
31 # Absolute filesystem path to the top-level project folder:
32 SITE_ROOT = dirname(DJANGO_ROOT)
35 SITE_NAME = basename(DJANGO_ROOT)
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
43 ########## DEBUG CONFIGURATION
44 # See: https://docs.djangoproject.com/en/dev/ref/settings/#debug
47 # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-debug
48 TEMPLATE_DEBUG = DEBUG
49 ########## END DEBUG CONFIGURATION
52 ########## MANAGER CONFIGURATION
53 # See: https://docs.djangoproject.com/en/dev/ref/settings/#admins
55 ('Seth Woodworth', 'seth@finalsclub.org'),
56 ('Charles Holbrow', 'charles@finalsclub.org'),
57 ('Andrew Magliozzi', 'andrew@finalsclub.org'),
60 # See: https://docs.djangoproject.com/en/dev/ref/settings/#managers
62 ########## END MANAGER CONFIGURATION
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
71 ########## GENERAL CONFIGURATION
72 # See: https://docs.djangoproject.com/en/dev/ref/settings/#time-zone
73 TIME_ZONE = 'America/New_York'
75 # See: https://docs.djangoproject.com/en/dev/ref/settings/#language-code
76 LANGUAGE_CODE = 'en-us'
78 # See: https://docs.djangoproject.com/en/dev/ref/settings/#site-id
81 # See: https://docs.djangoproject.com/en/dev/ref/settings/#use-i18n
84 # See: https://docs.djangoproject.com/en/dev/ref/settings/#use-l10n
86 ########## END GENERAL CONFIGURATION
89 ########## MEDIA CONFIGURATION
90 # See: https://docs.djangoproject.com/en/dev/ref/settings/#media-root
91 MEDIA_ROOT = normpath(join(DJANGO_ROOT, 'media'))
93 # See: https://docs.djangoproject.com/en/dev/ref/settings/#media-url
95 ########## END MEDIA CONFIGURATION
98 ########## STATIC FILE CONFIGURATION
100 # See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#std:setting-STATICFILES_DIRS
102 normpath(join(DJANGO_ROOT, 'assets')),
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',
112 S3_URL = '//%s.s3.amazonaws.com/' % os.environ.get('AWS_STORAGE_BUCKET_NAME')
113 DEFAULT_FILE_STORAGE = os.environ['DEFAULT_FILE_STORAGE']
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')
119 ########## END STATIC FILE CONFIGURATION
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
128 ########## FIXTURE CONFIGURATION
129 # See: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-FIXTURE_DIRS
131 normpath(join(DJANGO_ROOT, 'fixtures')),
133 ########## END FIXTURE CONFIGURATION
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',
149 # allauth specific context processors
150 "allauth.account.context_processors.account",
151 "allauth.socialaccount.context_processors.socialaccount",
154 # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-loaders
156 'django.template.loaders.filesystem.Loader',
157 'django.template.loaders.app_directories.Loader',
160 # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-dirs
162 normpath(join(DJANGO_ROOT, 'templates')),
164 ########## END TEMPLATE CONFIGURATION
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',
173 # Version control middleware.
174 'reversion.middleware.RevisionMiddleware',
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',
183 ########## END MIDDLEWARE CONFIGURATION
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
192 ########## APP CONFIGURATION
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',
202 # Useful template tags:
203 'django.contrib.humanize',
205 # grappelli django-admin improvment, must be added before admin
208 # Admin panel and documentation:
209 'django.contrib.admin',
210 'django.contrib.admindocs',
214 # Database migration helpers:
217 # Static file management:
220 # Asynchronous task queue:
223 # Tagging https://github.com/yedpodtrzitko/django-taggit
229 # AJAX endpoints for autocompletion
231 'ajax_select_cascade',
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',
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',
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
258 ########## AUTHENTICATION
260 AUTHENTICATION_BACKENDS = (
261 # Needed to login by username in Django admin, regardless of `allauth`
262 "django.contrib.auth.backends.ModelBackend",
264 # `allauth` specific authentication methods, such as login by e-mail
265 "allauth.account.auth_backends.AuthenticationBackend",
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 = '/'
283 AUTH_PROFILE_MODULE = 'users.UserProfile'
285 ######### END AUTHENTICATION
287 ########## LOGGING CONFIGURATION
288 # See: https://docs.djangoproject.com/en/dev/ref/settings/#logging
291 'disable_existing_loggers': False,
293 'require_debug_false': {
294 '()': 'django.utils.log.RequireDebugFalse'
300 'class': 'logging.StreamHandler'
304 'filters': ['require_debug_false'],
305 'class': 'django.utils.log.AdminEmailHandler'
310 'handlers': ['console'],
314 'handlers': ['mail_admins'],
320 ########## END LOGGING CONFIGURATION
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)
327 # See: http://celery.github.com/celery/django/
329 ########## END CELERY CONFIGURATION
332 ########## WSGI CONFIGURATION
333 # See: https://docs.djangoproject.com/en/dev/ref/settings/#wsgi-application
334 WSGI_APPLICATION = 'wsgi.application'
335 ########## END WSGI CONFIGURATION
338 ########## COMPRESSION CONFIGURATION
339 # See: http://django_compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_ENABLED
340 COMPRESS_ENABLED = True
342 # See: http://django_compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_CSS_FILTERS
343 COMPRESS_CSS_FILTERS = [
344 'compressor.filters.template.TemplateFilter',
347 # See: http://django_compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_JS_FILTERS
348 COMPRESS_JS_FILTERS = [
349 'compressor.filters.template.TemplateFilter',
351 ########## END COMPRESSION CONFIGURATION
353 ########## SESSION CONFIGURATION
355 SESSION_ENGINE = 'django.contrib.sessions.backends.db'
356 SESSION_COOKIE_AGE = 63072000 # 2 years in seconds
358 ########## END SESSION CONFIGURATION
360 ########## TAGGIT CONFIGURATION
361 # From https://github.com/yedpodtrzitko/django-taggit
364 TAGGIT_FORCE_LOWERCASE = True
366 # Ignore common stopwords
367 TAGGIT_STOPWORDS = [u'a', u'an', u'and', u'be', u'from', u'of']
369 ########## END TAGGIT CONFIGURATION
372 ########## HONEYPOT CONFIGURATION
373 # parts of this code borrow from
374 # https://github.com/sunlightlabs/django-honeypot
375 HONEYPOT_FIELD_NAME = "instruction_url" # see that "_url"? bots gotta want that.
377 HONEYPOT_LABEL = "Humans, leave this blank so we can prevent robots from submitting bogus courses"
378 HONEYPOT_ERROR = "You did not follow directions."
379 ########## END HONEYPOT CONFIGURATION
382 ########## SOUTH CONFIGURATION
383 SOUTH_MIGRATION_MODULES = {
384 'taggit': 'taggit.south_migrations',
386 ########## END SOUTH CONFIGURATION
388 ########## AJAX SELECTS CONFIGURATION
389 AJAX_SELECT_BOOTSTRAP = False
390 ########## END AJAX SELECTS CONFIGURATION
393 ########## TESTING CONFIGURATION
394 TESTING = 'test' in sys.argv
395 ########## END TESTING CONFIGURATION