3 # Copyright (C) 2012 FinalsClub Foundation
4 """ Common settings and globals. """
7 from datetime import timedelta
9 from os.path import abspath, basename, dirname, join, normpath
12 from djcelery import setup_loader
14 from karmaworld.secret.filepicker import FILEPICKER_API_KEY as fp_api
16 FILEPICKER_API_KEY = fp_api
17 FILEPICKER_INPUT_TYPE = 'filepicker'
19 from karmaworld.secret.static_s3 import *
21 SERIALIZATION_MODULES = {'json-pretty': 'karmaworld.apps.serializers.json_pretty'}
24 ########## REQUIRED SECURITY CONFIGURATION
25 # See: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-ALLOWED_HOSTS
26 # The hosts that this server runs from.
28 '127.0.0.1', # for dev systems / VMs, but should be safe enough
29 'localhost', # for dev systems / VMs, but should be safe enough
30 'beta.karmanotes.org',
33 'quiz.karmanotes.org',
35 ########## END SECURITY CONFIGURATION
37 ########## PATH CONFIGURATION
38 # Absolute filesystem path to the Django project directory:
39 DJANGO_ROOT = dirname(dirname(abspath(__file__)))
41 # Absolute filesystem path to the top-level project folder:
42 SITE_ROOT = dirname(DJANGO_ROOT)
45 SITE_NAME = basename(DJANGO_ROOT)
47 # Add our project to our pythonpath, this way we don't need to type our project
48 # name in our dotted import paths:
49 path.append(DJANGO_ROOT)
50 ########## END PATH CONFIGURATION
53 ########## DEBUG CONFIGURATION
54 # See: https://docs.djangoproject.com/en/dev/ref/settings/#debug
57 # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-debug
58 TEMPLATE_DEBUG = DEBUG
59 ########## END DEBUG CONFIGURATION
62 ########## MANAGER CONFIGURATION
63 # See: https://docs.djangoproject.com/en/dev/ref/settings/#admins
65 ('Seth Woodworth', 'seth@finalsclub.org'),
66 ('Charles Holbrow', 'charles@finalsclub.org'),
67 ('Andrew Magliozzi', 'andrew@finalsclub.org'),
70 # See: https://docs.djangoproject.com/en/dev/ref/settings/#managers
72 ########## END MANAGER CONFIGURATION
75 ########## DATABASE CONFIGURATION
76 # See: https://docs.djangoproject.com/en/dev/ref/settings/#databases
79 'ENGINE': 'django.db.backends.',
87 ########## END DATABASE CONFIGURATION
90 ########## GENERAL CONFIGURATION
91 # See: https://docs.djangoproject.com/en/dev/ref/settings/#time-zone
92 TIME_ZONE = 'America/New_York'
94 # See: https://docs.djangoproject.com/en/dev/ref/settings/#language-code
95 LANGUAGE_CODE = 'en-us'
97 # See: https://docs.djangoproject.com/en/dev/ref/settings/#site-id
100 # See: https://docs.djangoproject.com/en/dev/ref/settings/#use-i18n
103 # See: https://docs.djangoproject.com/en/dev/ref/settings/#use-l10n
105 ########## END GENERAL CONFIGURATION
108 ########## MEDIA CONFIGURATION
109 # See: https://docs.djangoproject.com/en/dev/ref/settings/#media-root
110 MEDIA_ROOT = normpath(join(DJANGO_ROOT, 'media'))
112 # See: https://docs.djangoproject.com/en/dev/ref/settings/#media-url
113 MEDIA_URL = '/media/'
114 ########## END MEDIA CONFIGURATION
117 ########## STATIC FILE CONFIGURATION
119 # See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#std:setting-STATICFILES_DIRS
121 normpath(join(DJANGO_ROOT, 'assets')),
124 # See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#staticfiles-finders
125 STATICFILES_FINDERS = (
126 'django.contrib.staticfiles.finders.FileSystemFinder',
127 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
128 'compressor.finders.CompressorFinder',
130 ########## END STATIC FILE CONFIGURATION
133 ########## SECRET CONFIGURATION
134 # See: https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
135 SECRET_KEY = r"(s1k!&^7l28k&nrm2ek(qqo&19%y(zn#=^zq_*ur2@irjun0x4"
136 ########## END SECRET CONFIGURATION
139 ########## FIXTURE CONFIGURATION
140 # See: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-FIXTURE_DIRS
142 normpath(join(DJANGO_ROOT, 'fixtures')),
144 ########## END FIXTURE CONFIGURATION
147 ########## TEMPLATE CONFIGURATION
148 # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-context-processors
149 TEMPLATE_CONTEXT_PROCESSORS = (
150 'django.contrib.auth.context_processors.auth',
151 'django.core.context_processors.debug',
152 'django.core.context_processors.i18n',
153 'django.core.context_processors.media',
154 'django.core.context_processors.static',
155 'django.core.context_processors.tz',
156 'django.contrib.messages.context_processors.messages',
157 'django.core.context_processors.request',
158 'karmaworld.apps.notes.context_processors.s3_url',
160 # allauth specific context processors
161 "allauth.account.context_processors.account",
162 "allauth.socialaccount.context_processors.socialaccount",
165 # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-loaders
167 'django.template.loaders.filesystem.Loader',
168 'django.template.loaders.app_directories.Loader',
171 # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-dirs
173 normpath(join(DJANGO_ROOT, 'templates')),
175 ########## END TEMPLATE CONFIGURATION
178 ########## MIDDLEWARE CONFIGURATION
179 # See: https://docs.djangoproject.com/en/dev/ref/settings/#middleware-classes
180 MIDDLEWARE_CLASSES = (
181 # Use GZip compression to reduce bandwidth.
182 'django.middleware.gzip.GZipMiddleware',
184 # Version control middleware.
185 'reversion.middleware.RevisionMiddleware',
187 # Default Django middleware.
188 'django.middleware.common.CommonMiddleware',
189 'django.contrib.sessions.middleware.SessionMiddleware',
190 'django.middleware.csrf.CsrfViewMiddleware',
191 'django.contrib.auth.middleware.AuthenticationMiddleware',
192 'django.contrib.messages.middleware.MessageMiddleware',
194 ########## END MIDDLEWARE CONFIGURATION
197 ########## URL CONFIGURATION
198 # See: https://docs.djangoproject.com/en/dev/ref/settings/#root-urlconf
199 ROOT_URLCONF = '%s.urls' % SITE_NAME
200 ########## END URL CONFIGURATION
203 ########## APP CONFIGURATION
205 # Default Django apps:
206 'django.contrib.auth',
207 'django.contrib.contenttypes',
208 'django.contrib.sessions',
209 'django.contrib.sites',
210 'django.contrib.messages',
211 'django.contrib.staticfiles',
213 # Useful template tags:
214 'django.contrib.humanize',
216 # grappelli django-admin improvment, must be added before admin
219 # Admin panel and documentation:
220 'django.contrib.admin',
221 'django.contrib.admindocs',
225 # Database migration helpers:
228 # Static file management:
231 # Asynchronous task queue:
234 # Tagging https://github.com/yedpodtrzitko/django-taggit
240 # AJAX endpoints for autocompletion
242 'ajax_select_cascade',
246 'allauth.socialaccount',
247 # ... include the providers you want to enable:
248 'allauth.socialaccount.providers.facebook',
249 'allauth.socialaccount.providers.google',
250 'allauth.socialaccount.providers.twitter',
252 # Added to make quizzes moderation nicer
258 'karmaworld.apps.notes',
259 'karmaworld.apps.courses',
260 'karmaworld.apps.document_upload',
261 'karmaworld.apps.users',
262 'karmaworld.apps.moderation',
263 'karmaworld.apps.licenses',
264 'karmaworld.apps.quizzes',
267 # See: https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps
268 INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS
269 ########## END APP CONFIGURATION
272 ########## AUTHENTICATION
274 AUTHENTICATION_BACKENDS = (
275 # Needed to login by username in Django admin, regardless of `allauth`
276 "django.contrib.auth.backends.ModelBackend",
278 # `allauth` specific authentication methods, such as login by e-mail
279 "allauth.account.auth_backends.AuthenticationBackend",
282 ACCOUNT_EMAIL_REQUIRED = True
283 ACCOUNT_AUTHENTICATION_METHOD = "email"
284 ACCOUNT_CONFIRM_EMAIL_ON_GET = False
285 ACCOUNT_EMAIL_VERIFICATION = "optional"
286 ACCOUNT_EMAIL_SUBJECT_PREFIX = "KarmaNotes.org -- "
287 ACCOUNT_USERNAME_REQUIRED = True
288 SOCIALACCOUNT_EMAIL_REQUIRED = True
289 SOCIALACCOUNT_EMAIL_VERIFICATION = "optional"
290 SOCIALACCOUNT_QUERY_EMAIL = True
291 SOCIALACCOUNT_AUTO_SIGNUP = False
292 ACCOUNT_USER_DISPLAY = 'karmaworld.apps.users.models.user_display_name'
293 ACCOUNT_SIGNUP_FORM_CLASS = 'karmaworld.apps.users.forms.SignupForm'
294 ACCOUNT_DEFAULT_HTTP_PROTOCOL = 'https'
296 AUTH_PROFILE_MODULE = 'users.UserProfile'
298 ######### END AUTHENTICATION
300 ########## LOGGING CONFIGURATION
301 # See: https://docs.djangoproject.com/en/dev/ref/settings/#logging
304 'disable_existing_loggers': False,
306 'require_debug_false': {
307 '()': 'django.utils.log.RequireDebugFalse'
313 'class': 'logging.StreamHandler'
317 'filters': ['require_debug_false'],
318 'class': 'django.utils.log.AdminEmailHandler'
323 'handlers': ['console'],
327 'handlers': ['mail_admins'],
333 ########## END LOGGING CONFIGURATION
336 ########## CELERY CONFIGURATION
337 # See: http://celery.readthedocs.org/en/latest/configuration.html#celery-task-result-expires
338 CELERY_TASK_RESULT_EXPIRES = timedelta(minutes=30)
340 # See: http://celery.github.com/celery/django/
342 ########## END CELERY CONFIGURATION
345 ########## WSGI CONFIGURATION
346 # See: https://docs.djangoproject.com/en/dev/ref/settings/#wsgi-application
347 WSGI_APPLICATION = 'wsgi.application'
348 ########## END WSGI CONFIGURATION
351 ########## COMPRESSION CONFIGURATION
352 # See: http://django_compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_ENABLED
353 COMPRESS_ENABLED = True
355 # See: http://django_compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_CSS_FILTERS
356 COMPRESS_CSS_FILTERS = [
357 'compressor.filters.template.TemplateFilter',
360 # See: http://django_compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_JS_FILTERS
361 COMPRESS_JS_FILTERS = [
362 'compressor.filters.template.TemplateFilter',
364 ########## END COMPRESSION CONFIGURATION
366 ########## SESSION CONFIGURATION
368 SESSION_ENGINE = 'django.contrib.sessions.backends.db'
369 SESSION_COOKIE_AGE = 63072000 # 2 years in seconds
371 ########## END SESSION CONFIGURATION
373 ########## TAGGIT CONFIGURATION
374 # From https://github.com/yedpodtrzitko/django-taggit
377 TAGGIT_FORCE_LOWERCASE = True
379 # Ignore common stopwords
380 TAGGIT_STOPWORDS = [u'a', u'an', u'and', u'be', u'from', u'of']
382 ########## END TAGGIT CONFIGURATION
385 ########## HONEYPOT CONFIGURATION
386 # parts of this code borrow from
387 # https://github.com/sunlightlabs/django-honeypot
388 HONEYPOT_FIELD_NAME = "instruction_url" # see that "_url"? bots gotta want that.
390 HONEYPOT_LABEL = "Do not fill in this field <span class='required-field'>(we need to make sure you're not a robot)</span>"
391 HONEYPOT_ERROR = "You did not follow directions."
392 ########## END HONEYPOT CONFIGURATION
395 ########## TESTING CONFIGURATION
396 TESTING = 'test' in sys.argv
397 ########## END TESTING CONFIGURATION