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
18 from karmaworld.secret.static_s3 import *
20 SERIALIZATION_MODULES = {'json-pretty': 'karmaworld.apps.serializers.json_pretty'}
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.
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',
33 ########## END SECURITY CONFIGURATION
35 ########## PATH CONFIGURATION
36 # Absolute filesystem path to the Django project directory:
37 DJANGO_ROOT = dirname(dirname(abspath(__file__)))
39 # Absolute filesystem path to the top-level project folder:
40 SITE_ROOT = dirname(DJANGO_ROOT)
43 SITE_NAME = basename(DJANGO_ROOT)
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
51 ########## DEBUG CONFIGURATION
52 # See: https://docs.djangoproject.com/en/dev/ref/settings/#debug
55 # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-debug
56 TEMPLATE_DEBUG = DEBUG
57 ########## END DEBUG CONFIGURATION
60 ########## MANAGER CONFIGURATION
61 # See: https://docs.djangoproject.com/en/dev/ref/settings/#admins
63 ('Seth Woodworth', 'seth@finalsclub.org'),
64 ('Charles Holbrow', 'charles@finalsclub.org'),
65 ('Andrew Magliozzi', 'andrew@finalsclub.org'),
68 # See: https://docs.djangoproject.com/en/dev/ref/settings/#managers
70 ########## END MANAGER CONFIGURATION
73 ########## DATABASE CONFIGURATION
74 # See: https://docs.djangoproject.com/en/dev/ref/settings/#databases
77 'ENGINE': 'django.db.backends.',
85 ########## END DATABASE CONFIGURATION
88 ########## GENERAL CONFIGURATION
89 # See: https://docs.djangoproject.com/en/dev/ref/settings/#time-zone
90 TIME_ZONE = 'America/New_York'
92 # See: https://docs.djangoproject.com/en/dev/ref/settings/#language-code
93 LANGUAGE_CODE = 'en-us'
95 # See: https://docs.djangoproject.com/en/dev/ref/settings/#site-id
98 # See: https://docs.djangoproject.com/en/dev/ref/settings/#use-i18n
101 # See: https://docs.djangoproject.com/en/dev/ref/settings/#use-l10n
103 ########## END GENERAL CONFIGURATION
106 ########## MEDIA CONFIGURATION
107 # See: https://docs.djangoproject.com/en/dev/ref/settings/#media-root
108 MEDIA_ROOT = normpath(join(DJANGO_ROOT, 'media'))
110 # See: https://docs.djangoproject.com/en/dev/ref/settings/#media-url
111 MEDIA_URL = '/media/'
112 ########## END MEDIA CONFIGURATION
115 ########## STATIC FILE CONFIGURATION
117 # See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#std:setting-STATICFILES_DIRS
119 normpath(join(DJANGO_ROOT, 'assets')),
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',
128 ########## END STATIC FILE CONFIGURATION
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
137 ########## FIXTURE CONFIGURATION
138 # See: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-FIXTURE_DIRS
140 normpath(join(DJANGO_ROOT, 'fixtures')),
142 ########## END FIXTURE CONFIGURATION
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',
158 # allauth specific context processors
159 "allauth.account.context_processors.account",
160 "allauth.socialaccount.context_processors.socialaccount",
163 # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-loaders
165 'django.template.loaders.filesystem.Loader',
166 'django.template.loaders.app_directories.Loader',
169 # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-dirs
171 normpath(join(DJANGO_ROOT, 'templates')),
173 ########## END TEMPLATE CONFIGURATION
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',
182 # Version control middleware.
183 'reversion.middleware.RevisionMiddleware',
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',
192 ########## END MIDDLEWARE CONFIGURATION
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
201 ########## APP CONFIGURATION
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',
211 # Useful template tags:
212 'django.contrib.humanize',
214 # grappelli django-admin improvment, must be added before admin
217 # Admin panel and documentation:
218 'django.contrib.admin',
219 'django.contrib.admindocs',
223 # Database migration helpers:
226 # Static file management:
229 # Asynchronous task queue:
232 # Tagging https://github.com/yedpodtrzitko/django-taggit
238 # AJAX endpoints for autocompletion
240 'ajax_select_cascade',
244 'allauth.socialaccount',
245 # ... include the providers you want to enable:
246 'allauth.socialaccount.providers.facebook',
247 'allauth.socialaccount.providers.google',
248 'allauth.socialaccount.providers.twitter',
253 'karmaworld.apps.notes',
254 'karmaworld.apps.courses',
255 'karmaworld.apps.document_upload',
256 'karmaworld.apps.users',
257 'karmaworld.apps.moderation',
258 'karmaworld.apps.licenses',
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
266 ########## AUTHENTICATION
268 AUTHENTICATION_BACKENDS = (
269 # Needed to login by username in Django admin, regardless of `allauth`
270 "django.contrib.auth.backends.ModelBackend",
272 # `allauth` specific authentication methods, such as login by e-mail
273 "allauth.account.auth_backends.AuthenticationBackend",
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'
290 AUTH_PROFILE_MODULE = 'users.UserProfile'
292 ######### END AUTHENTICATION
294 ########## LOGGING CONFIGURATION
295 # See: https://docs.djangoproject.com/en/dev/ref/settings/#logging
298 'disable_existing_loggers': False,
300 'require_debug_false': {
301 '()': 'django.utils.log.RequireDebugFalse'
307 'class': 'logging.StreamHandler'
311 'filters': ['require_debug_false'],
312 'class': 'django.utils.log.AdminEmailHandler'
317 'handlers': ['console'],
321 'handlers': ['mail_admins'],
327 ########## END LOGGING CONFIGURATION
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)
334 # See: http://celery.github.com/celery/django/
336 ########## END CELERY CONFIGURATION
339 ########## WSGI CONFIGURATION
340 # See: https://docs.djangoproject.com/en/dev/ref/settings/#wsgi-application
341 WSGI_APPLICATION = 'wsgi.application'
342 ########## END WSGI CONFIGURATION
345 ########## COMPRESSION CONFIGURATION
346 # See: http://django_compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_ENABLED
347 COMPRESS_ENABLED = True
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',
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',
358 ########## END COMPRESSION CONFIGURATION
360 ########## SESSION CONFIGURATION
362 SESSION_ENGINE = 'django.contrib.sessions.backends.db'
363 SESSION_COOKIE_AGE = 63072000 # 2 years in seconds
365 ########## END SESSION CONFIGURATION
367 ########## TAGGIT CONFIGURATION
368 # From https://github.com/yedpodtrzitko/django-taggit
371 TAGGIT_FORCE_LOWERCASE = True
373 # Ignore common stopwords
374 TAGGIT_STOPWORDS = [u'a', u'an', u'and', u'be', u'from', u'of']
376 ########## END TAGGIT CONFIGURATION
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.
384 HONEYPOT_LABEL = "Do not fill in this field:"
385 HONEYPOT_ERROR = "You did not follow directions."
386 ########## END HONEYPOT CONFIGURATION
389 ########## TESTING CONFIGURATION
390 TESTING = 'test' in sys.argv
391 ########## END TESTING CONFIGURATION