3 # Copyright (C) 2012 FinalsClub Foundation
4 """ Common settings and globals. """
5 from datetime import timedelta
7 from os.path import abspath, basename, dirname, join, normpath
9 from djcelery import setup_loader
10 import dj_database_url
11 from karmaworld.secret.filepicker import FILEPICKER_API_KEY as fp_api
13 FILEPICKER_API_KEY = fp_api
14 FILEPICKER_INPUT_TYPE = 'filepicker'
16 from karmaworld.secret.static_s3 import *
18 SERIALIZATION_MODULES = {'json-pretty': 'karmaworld.apps.serializers.json_pretty'}
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.
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',
30 'quiz.karmanotes.org',
32 ########## END SECURITY CONFIGURATION
34 ########## PATH CONFIGURATION
35 # Absolute filesystem path to the Django project directory:
36 DJANGO_ROOT = dirname(dirname(abspath(__file__)))
38 # Absolute filesystem path to the top-level project folder:
39 SITE_ROOT = dirname(DJANGO_ROOT)
42 SITE_NAME = basename(DJANGO_ROOT)
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
50 ########## DEBUG CONFIGURATION
51 # See: https://docs.djangoproject.com/en/dev/ref/settings/#debug
54 # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-debug
55 TEMPLATE_DEBUG = DEBUG
56 ########## END DEBUG CONFIGURATION
59 ########## MANAGER CONFIGURATION
60 # See: https://docs.djangoproject.com/en/dev/ref/settings/#admins
62 ('Seth Woodworth', 'seth@finalsclub.org'),
63 ('Charles Holbrow', 'charles@finalsclub.org'),
64 ('Andrew Magliozzi', 'andrew@finalsclub.org'),
67 # See: https://docs.djangoproject.com/en/dev/ref/settings/#managers
69 ########## END MANAGER CONFIGURATION
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
78 ########## GENERAL CONFIGURATION
79 # See: https://docs.djangoproject.com/en/dev/ref/settings/#time-zone
80 TIME_ZONE = 'America/New_York'
82 # See: https://docs.djangoproject.com/en/dev/ref/settings/#language-code
83 LANGUAGE_CODE = 'en-us'
85 # See: https://docs.djangoproject.com/en/dev/ref/settings/#site-id
88 # See: https://docs.djangoproject.com/en/dev/ref/settings/#use-i18n
91 # See: https://docs.djangoproject.com/en/dev/ref/settings/#use-l10n
93 ########## END GENERAL CONFIGURATION
96 ########## MEDIA CONFIGURATION
97 # See: https://docs.djangoproject.com/en/dev/ref/settings/#media-root
98 MEDIA_ROOT = normpath(join(DJANGO_ROOT, 'media'))
100 # See: https://docs.djangoproject.com/en/dev/ref/settings/#media-url
101 MEDIA_URL = '/media/'
102 ########## END MEDIA CONFIGURATION
105 ########## STATIC FILE CONFIGURATION
107 # See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#std:setting-STATICFILES_DIRS
109 normpath(join(DJANGO_ROOT, 'assets')),
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',
118 ########## END STATIC FILE CONFIGURATION
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
127 ########## FIXTURE CONFIGURATION
128 # See: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-FIXTURE_DIRS
130 normpath(join(DJANGO_ROOT, 'fixtures')),
132 ########## END FIXTURE CONFIGURATION
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',
148 # allauth specific context processors
149 "allauth.account.context_processors.account",
150 "allauth.socialaccount.context_processors.socialaccount",
153 # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-loaders
155 'django.template.loaders.filesystem.Loader',
156 'django.template.loaders.app_directories.Loader',
159 # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-dirs
161 normpath(join(DJANGO_ROOT, 'templates')),
163 ########## END TEMPLATE CONFIGURATION
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',
172 # Version control middleware.
173 'reversion.middleware.RevisionMiddleware',
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',
182 ########## END MIDDLEWARE CONFIGURATION
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
191 ########## APP CONFIGURATION
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',
201 # Useful template tags:
202 'django.contrib.humanize',
204 # grappelli django-admin improvment, must be added before admin
207 # Admin panel and documentation:
208 'django.contrib.admin',
209 'django.contrib.admindocs',
213 # Database migration helpers:
216 # Static file management:
219 # Asynchronous task queue:
222 # Tagging https://github.com/yedpodtrzitko/django-taggit
228 # AJAX endpoints for autocompletion
230 'ajax_select_cascade',
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',
240 # Added to make quizzes moderation nicer
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',
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
260 ########## AUTHENTICATION
262 AUTHENTICATION_BACKENDS = (
263 # Needed to login by username in Django admin, regardless of `allauth`
264 "django.contrib.auth.backends.ModelBackend",
266 # `allauth` specific authentication methods, such as login by e-mail
267 "allauth.account.auth_backends.AuthenticationBackend",
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 = '/'
285 AUTH_PROFILE_MODULE = 'users.UserProfile'
287 ######### END AUTHENTICATION
289 ########## LOGGING CONFIGURATION
290 # See: https://docs.djangoproject.com/en/dev/ref/settings/#logging
293 'disable_existing_loggers': False,
295 'require_debug_false': {
296 '()': 'django.utils.log.RequireDebugFalse'
302 'class': 'logging.StreamHandler'
306 'filters': ['require_debug_false'],
307 'class': 'django.utils.log.AdminEmailHandler'
312 'handlers': ['console'],
316 'handlers': ['mail_admins'],
322 ########## END LOGGING CONFIGURATION
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)
329 # See: http://celery.github.com/celery/django/
331 ########## END CELERY CONFIGURATION
334 ########## WSGI CONFIGURATION
335 # See: https://docs.djangoproject.com/en/dev/ref/settings/#wsgi-application
336 WSGI_APPLICATION = 'wsgi.application'
337 ########## END WSGI CONFIGURATION
340 ########## COMPRESSION CONFIGURATION
341 # See: http://django_compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_ENABLED
342 COMPRESS_ENABLED = True
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',
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',
353 ########## END COMPRESSION CONFIGURATION
355 ########## SESSION CONFIGURATION
357 SESSION_ENGINE = 'django.contrib.sessions.backends.db'
358 SESSION_COOKIE_AGE = 63072000 # 2 years in seconds
360 ########## END SESSION CONFIGURATION
362 ########## TAGGIT CONFIGURATION
363 # From https://github.com/yedpodtrzitko/django-taggit
366 TAGGIT_FORCE_LOWERCASE = True
368 # Ignore common stopwords
369 TAGGIT_STOPWORDS = [u'a', u'an', u'and', u'be', u'from', u'of']
371 ########## END TAGGIT CONFIGURATION
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.
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
384 ########## SOUTH CONFIGURATION
385 SOUTH_MIGRATION_MODULES = {
386 'taggit': 'taggit.south_migrations',
388 ########## END SOUTH CONFIGURATION
390 ########## AJAX SELECTS CONFIGURATION
391 AJAX_SELECT_BOOTSTRAP = False
392 ########## END AJAX SELECTS CONFIGURATION
395 ########## TESTING CONFIGURATION
396 TESTING = 'test' in sys.argv
397 ########## END TESTING CONFIGURATION