Find fonts correctly, don't load jquery twice
[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
6
7 from datetime import timedelta
8 import sys
9 from os.path import abspath, basename, dirname, join, normpath
10 from sys import path
11
12 from djcelery import setup_loader
13
14 from karmaworld.secret.filepicker import FILEPICKER_API_KEY as fp_api
15
16 FILEPICKER_API_KEY = fp_api
17 FILEPICKER_INPUT_TYPE = 'filepicker'
18
19 from karmaworld.secret.static_s3 import *
20
21 SERIALIZATION_MODULES = {'json-pretty': 'karmaworld.apps.serializers.json_pretty'}
22
23
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.
27 ALLOWED_HOSTS = [
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',
31     'www.karmanotes.org',
32     'karmanotes.org',
33     'quiz.karmanotes.org',
34 ]
35 ########## END SECURITY CONFIGURATION
36
37 ########## PATH CONFIGURATION
38 # Absolute filesystem path to the Django project directory:
39 DJANGO_ROOT = dirname(dirname(abspath(__file__)))
40
41 # Absolute filesystem path to the top-level project folder:
42 SITE_ROOT = dirname(DJANGO_ROOT)
43
44 # Site name:
45 SITE_NAME = basename(DJANGO_ROOT)
46
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
51
52
53 ########## DEBUG CONFIGURATION
54 # See: https://docs.djangoproject.com/en/dev/ref/settings/#debug
55 DEBUG = False
56
57 # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-debug
58 TEMPLATE_DEBUG = DEBUG
59 ########## END DEBUG CONFIGURATION
60
61
62 ########## MANAGER CONFIGURATION
63 # See: https://docs.djangoproject.com/en/dev/ref/settings/#admins
64 ADMINS = (
65     ('Seth Woodworth', 'seth@finalsclub.org'),
66     ('Charles Holbrow', 'charles@finalsclub.org'),
67     ('Andrew Magliozzi', 'andrew@finalsclub.org'),
68 )
69
70 # See: https://docs.djangoproject.com/en/dev/ref/settings/#managers
71 MANAGERS = ADMINS
72 ########## END MANAGER CONFIGURATION
73
74
75 ########## DATABASE CONFIGURATION
76 # See: https://docs.djangoproject.com/en/dev/ref/settings/#databases
77 DATABASES = {
78     'default': {
79         'ENGINE': 'django.db.backends.',
80         'NAME': '',
81         'USER': '',
82         'PASSWORD': '',
83         'HOST': '',
84         'PORT': '',
85     }
86 }
87 ########## END DATABASE CONFIGURATION
88
89
90 ########## GENERAL CONFIGURATION
91 # See: https://docs.djangoproject.com/en/dev/ref/settings/#time-zone
92 TIME_ZONE = 'America/New_York'
93
94 # See: https://docs.djangoproject.com/en/dev/ref/settings/#language-code
95 LANGUAGE_CODE = 'en-us'
96
97 # See: https://docs.djangoproject.com/en/dev/ref/settings/#site-id
98 SITE_ID = 1
99
100 # See: https://docs.djangoproject.com/en/dev/ref/settings/#use-i18n
101 USE_I18N = True
102
103 # See: https://docs.djangoproject.com/en/dev/ref/settings/#use-l10n
104 USE_L10N = True
105 ########## END GENERAL CONFIGURATION
106
107
108 ########## MEDIA CONFIGURATION
109 # See: https://docs.djangoproject.com/en/dev/ref/settings/#media-root
110 MEDIA_ROOT = normpath(join(DJANGO_ROOT, 'media'))
111
112 # See: https://docs.djangoproject.com/en/dev/ref/settings/#media-url
113 MEDIA_URL = '/media/'
114 ########## END MEDIA CONFIGURATION
115
116
117 ########## STATIC FILE CONFIGURATION
118
119 # See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#std:setting-STATICFILES_DIRS
120 STATICFILES_DIRS = (
121     normpath(join(DJANGO_ROOT, 'assets')),
122 )
123
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',
129 )
130 ########## END STATIC FILE CONFIGURATION
131
132
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
137
138
139 ########## FIXTURE CONFIGURATION
140 # See: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-FIXTURE_DIRS
141 FIXTURE_DIRS = (
142     normpath(join(DJANGO_ROOT, 'fixtures')),
143 )
144 ########## END FIXTURE CONFIGURATION
145
146
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',
159
160     # allauth specific context processors
161     "allauth.account.context_processors.account",
162     "allauth.socialaccount.context_processors.socialaccount",
163 )
164
165 # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-loaders
166 TEMPLATE_LOADERS = (
167     'django.template.loaders.filesystem.Loader',
168     'django.template.loaders.app_directories.Loader',
169 )
170
171 # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-dirs
172 TEMPLATE_DIRS = (
173     normpath(join(DJANGO_ROOT, 'templates')),
174 )
175 ########## END TEMPLATE CONFIGURATION
176
177
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',
183
184     # Version control middleware.
185     'reversion.middleware.RevisionMiddleware',
186
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',
193 )
194 ########## END MIDDLEWARE CONFIGURATION
195
196
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
201
202
203 ########## APP CONFIGURATION
204 DJANGO_APPS = (
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',
212
213     # Useful template tags:
214     'django.contrib.humanize',
215
216     # grappelli django-admin improvment, must be added before admin
217     'grappelli',
218
219     # Admin panel and documentation:
220     'django.contrib.admin',
221     'django.contrib.admindocs',
222 )
223
224 THIRD_PARTY_APPS = (
225     # Database migration helpers:
226     'south',
227
228     # Static file management:
229     'compressor',
230
231     # Asynchronous task queue:
232     'djcelery',
233
234     # Tagging https://github.com/yedpodtrzitko/django-taggit
235     'taggit',
236
237     # Version control
238     'reversion',
239
240     # AJAX endpoints for autocompletion
241     'ajax_select',
242     'ajax_select_cascade',
243
244     'allauth',
245     'allauth.account',
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',
251
252     # Added to make quizzes moderation nicer
253     'nested_inlines',
254 )
255
256 LOCAL_APPS = (
257     # file handling app
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',
265 )
266
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
270
271
272 ########## AUTHENTICATION
273
274 AUTHENTICATION_BACKENDS = (
275     # Needed to login by username in Django admin, regardless of `allauth`
276     "django.contrib.auth.backends.ModelBackend",
277
278     # `allauth` specific authentication methods, such as login by e-mail
279     "allauth.account.auth_backends.AuthenticationBackend",
280 )
281
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'
295
296 AUTH_PROFILE_MODULE = 'users.UserProfile'
297
298 ######### END AUTHENTICATION
299
300 ########## LOGGING CONFIGURATION
301 # See: https://docs.djangoproject.com/en/dev/ref/settings/#logging
302 LOGGING = {
303     'version': 1,
304     'disable_existing_loggers': False,
305     'filters': {
306          'require_debug_false': {
307              '()': 'django.utils.log.RequireDebugFalse'
308          }
309      },
310     'handlers': {
311         'console': {
312             'level': 'INFO',
313             'class': 'logging.StreamHandler'
314         },
315         'mail_admins': {
316             'level': 'ERROR',
317             'filters': ['require_debug_false'],
318             'class': 'django.utils.log.AdminEmailHandler'
319         }
320     },
321     'loggers': {
322         'django': {
323             'handlers': ['console'],
324             'level': 'INFO'
325         },
326         'django.request': {
327             'handlers': ['mail_admins'],
328             'level': 'ERROR',
329             'propagate': True
330         },
331     }
332 }
333 ########## END LOGGING CONFIGURATION
334
335
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)
339
340 # See: http://celery.github.com/celery/django/
341 setup_loader()
342 ########## END CELERY CONFIGURATION
343
344
345 ########## WSGI CONFIGURATION
346 # See: https://docs.djangoproject.com/en/dev/ref/settings/#wsgi-application
347 WSGI_APPLICATION = 'wsgi.application'
348 ########## END WSGI CONFIGURATION
349
350
351 ########## COMPRESSION CONFIGURATION
352 # See: http://django_compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_ENABLED
353 COMPRESS_ENABLED = True
354
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',
358 ]
359
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',
363 ]
364 ########## END COMPRESSION CONFIGURATION
365
366 ########## SESSION CONFIGURATION
367
368 SESSION_ENGINE = 'django.contrib.sessions.backends.db'
369 SESSION_COOKIE_AGE = 63072000    # 2 years in seconds
370
371 ########## END SESSION CONFIGURATION
372
373 ########## TAGGIT CONFIGURATION
374 # From https://github.com/yedpodtrzitko/django-taggit
375
376 # Use lowercase tags
377 TAGGIT_FORCE_LOWERCASE = True
378
379 # Ignore common stopwords
380 TAGGIT_STOPWORDS = [u'a', u'an', u'and', u'be', u'from', u'of']
381
382 ########## END TAGGIT CONFIGURATION
383
384
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.
389 HONEYPOT_VALUE = ""
390 HONEYPOT_LABEL = "Humans, leave this blank so we can prevent robots from submitting bogus courses"
391 HONEYPOT_ERROR = "You did not follow directions."
392 ########## END HONEYPOT CONFIGURATION
393
394
395 ########## SOUTH CONFIGURATION
396 SOUTH_MIGRATION_MODULES = {
397     'taggit': 'taggit.south_migrations',
398 }
399 ########## END SOUTH CONFIGURATION
400
401 ########## AJAX SELECTS CONFIGURATION
402 AJAX_SELECT_BOOTSTRAP = False
403 ########## END AJAX SELECTS CONFIGURATION
404
405
406 ########## TESTING CONFIGURATION
407 TESTING = 'test' in sys.argv
408 ########## END TESTING CONFIGURATION