80f30128d0d9d1b3ad2733d14f3d5c1bf04ce013
[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 from os.path import abspath, basename, dirname, join, normpath
9 from sys import path
10
11 from djcelery import setup_loader
12
13 from karmaworld.secret.filepicker import FILEPICKER_API_KEY as fp_api
14
15 FILEPICKER_API_KEY = fp_api
16
17 from karmaworld.secret.static_s3 import *
18
19 SERIALIZATION_MODULES = {'json-pretty': 'karmaworld.apps.serializers.json_pretty'}
20
21
22 ########## REQUIRED SECURITY CONFIGURATION
23 # See: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-ALLOWED_HOSTS
24 # The hosts that this server runs from.
25 ALLOWED_HOSTS = [
26     '127.0.0.1', # for dev systems / VMs, but should be safe enough
27     'localhost', # for dev systems / VMs, but should be safe enough
28     'beta.karmanotes.org',
29     'www.karmanotes.org',
30     'karmanotes.org',
31 ]
32 ########## END SECURITY CONFIGURATION
33
34 ########## PATH CONFIGURATION
35 # Absolute filesystem path to the Django project directory:
36 DJANGO_ROOT = dirname(dirname(abspath(__file__)))
37
38 # Absolute filesystem path to the top-level project folder:
39 SITE_ROOT = dirname(DJANGO_ROOT)
40
41 # Site name:
42 SITE_NAME = basename(DJANGO_ROOT)
43
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
48
49
50 ########## DEBUG CONFIGURATION
51 # See: https://docs.djangoproject.com/en/dev/ref/settings/#debug
52 DEBUG = False
53
54 # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-debug
55 TEMPLATE_DEBUG = DEBUG
56 ########## END DEBUG CONFIGURATION
57
58
59 ########## MANAGER CONFIGURATION
60 # See: https://docs.djangoproject.com/en/dev/ref/settings/#admins
61 ADMINS = (
62     ('Seth Woodworth', 'seth@finalsclub.org'),
63     ('Charles Holbrow', 'charles@finalsclub.org'),
64     ('Andrew Magliozzi', 'andrew@finalsclub.org'),
65 )
66
67 # See: https://docs.djangoproject.com/en/dev/ref/settings/#managers
68 MANAGERS = ADMINS
69 ########## END MANAGER CONFIGURATION
70
71
72 ########## DATABASE CONFIGURATION
73 # See: https://docs.djangoproject.com/en/dev/ref/settings/#databases
74 DATABASES = {
75     'default': {
76         'ENGINE': 'django.db.backends.',
77         'NAME': '',
78         'USER': '',
79         'PASSWORD': '',
80         'HOST': '',
81         'PORT': '',
82     }
83 }
84 ########## END DATABASE CONFIGURATION
85
86
87 ########## GENERAL CONFIGURATION
88 # See: https://docs.djangoproject.com/en/dev/ref/settings/#time-zone
89 TIME_ZONE = 'America/New_York'
90
91 # See: https://docs.djangoproject.com/en/dev/ref/settings/#language-code
92 LANGUAGE_CODE = 'en-us'
93
94 # See: https://docs.djangoproject.com/en/dev/ref/settings/#site-id
95 SITE_ID = 1
96
97 # See: https://docs.djangoproject.com/en/dev/ref/settings/#use-i18n
98 USE_I18N = True
99
100 # See: https://docs.djangoproject.com/en/dev/ref/settings/#use-l10n
101 USE_L10N = True
102 ########## END GENERAL CONFIGURATION
103
104
105 ########## MEDIA CONFIGURATION
106 # See: https://docs.djangoproject.com/en/dev/ref/settings/#media-root
107 MEDIA_ROOT = normpath(join(DJANGO_ROOT, 'media'))
108
109 # See: https://docs.djangoproject.com/en/dev/ref/settings/#media-url
110 MEDIA_URL = '/media/'
111 ########## END MEDIA CONFIGURATION
112
113
114 ########## STATIC FILE CONFIGURATION
115
116 # See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#std:setting-STATICFILES_DIRS
117 STATICFILES_DIRS = (
118     normpath(join(DJANGO_ROOT, 'assets')),
119 )
120
121 # See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#staticfiles-finders
122 STATICFILES_FINDERS = (
123     'django.contrib.staticfiles.finders.FileSystemFinder',
124     'django.contrib.staticfiles.finders.AppDirectoriesFinder',
125     'compressor.finders.CompressorFinder',
126 )
127 ########## END STATIC FILE CONFIGURATION
128
129
130 ########## SECRET CONFIGURATION
131 # See: https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
132 SECRET_KEY = r"(s1k!&^7l28k&nrm2ek(qqo&19%y(zn#=^zq_*ur2@irjun0x4"
133 ########## END SECRET CONFIGURATION
134
135
136 ########## FIXTURE CONFIGURATION
137 # See: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-FIXTURE_DIRS
138 FIXTURE_DIRS = (
139     normpath(join(DJANGO_ROOT, 'fixtures')),
140 )
141 ########## END FIXTURE CONFIGURATION
142
143
144 ########## TEMPLATE CONFIGURATION
145 # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-context-processors
146 TEMPLATE_CONTEXT_PROCESSORS = (
147     'django.contrib.auth.context_processors.auth',
148     'django.core.context_processors.debug',
149     'django.core.context_processors.i18n',
150     'django.core.context_processors.media',
151     'django.core.context_processors.static',
152     'django.core.context_processors.tz',
153     'django.contrib.messages.context_processors.messages',
154     'django.core.context_processors.request',
155     'karmaworld.apps.notes.context_processors.s3_url',
156
157     # allauth specific context processors
158     "allauth.account.context_processors.account",
159     "allauth.socialaccount.context_processors.socialaccount",
160 )
161
162 # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-loaders
163 TEMPLATE_LOADERS = (
164     'django.template.loaders.filesystem.Loader',
165     'django.template.loaders.app_directories.Loader',
166 )
167
168 # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-dirs
169 TEMPLATE_DIRS = (
170     normpath(join(DJANGO_ROOT, 'templates')),
171 )
172 ########## END TEMPLATE CONFIGURATION
173
174
175 ########## MIDDLEWARE CONFIGURATION
176 # See: https://docs.djangoproject.com/en/dev/ref/settings/#middleware-classes
177 MIDDLEWARE_CLASSES = (
178     # Use GZip compression to reduce bandwidth.
179     'django.middleware.gzip.GZipMiddleware',
180
181     # Version control middleware.
182     'reversion.middleware.RevisionMiddleware',
183
184     # Default Django middleware.
185     'django.middleware.common.CommonMiddleware',
186     'django.contrib.sessions.middleware.SessionMiddleware',
187     'django.middleware.csrf.CsrfViewMiddleware',
188     'django.contrib.auth.middleware.AuthenticationMiddleware',
189     'django.contrib.messages.middleware.MessageMiddleware',
190 )
191 ########## END MIDDLEWARE CONFIGURATION
192
193
194 ########## URL CONFIGURATION
195 # See: https://docs.djangoproject.com/en/dev/ref/settings/#root-urlconf
196 ROOT_URLCONF = '%s.urls' % SITE_NAME
197 ########## END URL CONFIGURATION
198
199
200 ########## APP CONFIGURATION
201 DJANGO_APPS = (
202     # Default Django apps:
203     'django.contrib.auth',
204     'django.contrib.contenttypes',
205     'django.contrib.sessions',
206     'django.contrib.sites',
207     'django.contrib.messages',
208     'django.contrib.staticfiles',
209
210     # Useful template tags:
211     'django.contrib.humanize',
212
213     # grappelli django-admin improvment, must be added before admin
214     'grappelli',
215
216     # Admin panel and documentation:
217     'django.contrib.admin',
218     'django.contrib.admindocs',
219 )
220
221 THIRD_PARTY_APPS = (
222     # Database migration helpers:
223     'south',
224
225     # Static file management:
226     'compressor',
227
228     # Asynchronous task queue:
229     'djcelery',
230
231     # Tagging https://github.com/yedpodtrzitko/django-taggit
232     'taggit',
233
234     # Version control
235     'reversion',
236
237     'allauth',
238     'allauth.account',
239     'allauth.socialaccount',
240     # ... include the providers you want to enable:
241     'allauth.socialaccount.providers.facebook',
242     'allauth.socialaccount.providers.google',
243     'allauth.socialaccount.providers.twitter',
244
245     # Added to make quizzes moderation nicer
246     'nested_inlines',
247 )
248
249 LOCAL_APPS = (
250     # file handling app
251     'karmaworld.apps.notes',
252     'karmaworld.apps.courses',
253     'karmaworld.apps.document_upload',
254     'karmaworld.apps.users',
255     'karmaworld.apps.moderation',
256     'karmaworld.apps.licenses',
257     'karmaworld.apps.quizzes',
258 )
259
260 # See: https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps
261 INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS
262 ########## END APP CONFIGURATION
263
264
265 ########## AUTHENTICATION
266
267 AUTHENTICATION_BACKENDS = (
268     # Needed to login by username in Django admin, regardless of `allauth`
269     "django.contrib.auth.backends.ModelBackend",
270
271     # `allauth` specific authentication methods, such as login by e-mail
272     "allauth.account.auth_backends.AuthenticationBackend",
273 )
274
275 ACCOUNT_EMAIL_REQUIRED = True
276 ACCOUNT_AUTHENTICATION_METHOD = "email"
277 ACCOUNT_CONFIRM_EMAIL_ON_GET = False
278 ACCOUNT_EMAIL_VERIFICATION = "optional"
279 ACCOUNT_EMAIL_SUBJECT_PREFIX = "KarmaNotes.org -- "
280 ACCOUNT_USERNAME_REQUIRED = True
281 SOCIALACCOUNT_EMAIL_REQUIRED = True
282 SOCIALACCOUNT_EMAIL_VERIFICATION = "optional"
283 SOCIALACCOUNT_QUERY_EMAIL = True
284 SOCIALACCOUNT_AUTO_SIGNUP = False
285 ACCOUNT_USER_DISPLAY = 'karmaworld.apps.users.models.user_display_name'
286 ACCOUNT_SIGNUP_FORM_CLASS = 'karmaworld.apps.users.forms.SignupForm'
287 ACCOUNT_DEFAULT_HTTP_PROTOCOL = 'https'
288
289 AUTH_PROFILE_MODULE = 'users.UserProfile'
290
291 ######### END AUTHENTICATION
292
293 ########## LOGGING CONFIGURATION
294 # See: https://docs.djangoproject.com/en/dev/ref/settings/#logging
295 LOGGING = {
296     'version': 1,
297     'disable_existing_loggers': False,
298     'filters': {
299          'require_debug_false': {
300              '()': 'django.utils.log.RequireDebugFalse'
301          }
302      },
303     'handlers': {
304         'console': {
305             'level': 'INFO',
306             'class': 'logging.StreamHandler'
307         },
308         'mail_admins': {
309             'level': 'ERROR',
310             'filters': ['require_debug_false'],
311             'class': 'django.utils.log.AdminEmailHandler'
312         }
313     },
314     'loggers': {
315         'django': {
316             'handlers': ['console'],
317             'level': 'INFO'
318         },
319         'django.request': {
320             'handlers': ['mail_admins'],
321             'level': 'ERROR',
322             'propagate': True
323         },
324     }
325 }
326 ########## END LOGGING CONFIGURATION
327
328
329 ########## CELERY CONFIGURATION
330 # See: http://celery.readthedocs.org/en/latest/configuration.html#celery-task-result-expires
331 CELERY_TASK_RESULT_EXPIRES = timedelta(minutes=30)
332
333 # See: http://celery.github.com/celery/django/
334 setup_loader()
335 ########## END CELERY CONFIGURATION
336
337
338 ########## WSGI CONFIGURATION
339 # See: https://docs.djangoproject.com/en/dev/ref/settings/#wsgi-application
340 WSGI_APPLICATION = 'wsgi.application'
341 ########## END WSGI CONFIGURATION
342
343
344 ########## COMPRESSION CONFIGURATION
345 # See: http://django_compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_ENABLED
346 COMPRESS_ENABLED = True
347
348 # See: http://django_compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_CSS_FILTERS
349 COMPRESS_CSS_FILTERS = [
350     'compressor.filters.template.TemplateFilter',
351 ]
352
353 # See: http://django_compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_JS_FILTERS
354 COMPRESS_JS_FILTERS = [
355     'compressor.filters.template.TemplateFilter',
356 ]
357 ########## END COMPRESSION CONFIGURATION
358
359 ########## SESSION CONFIGURATION
360
361 SESSION_ENGINE = 'django.contrib.sessions.backends.db'
362 SESSION_COOKIE_AGE = 63072000    # 2 years in seconds
363
364 ########## END SESSION CONFIGURATION
365
366 ########## TAGGIT CONFIGURATION
367 # From https://github.com/yedpodtrzitko/django-taggit
368
369 # Use lowercase tags
370 TAGGIT_FORCE_LOWERCASE = True
371
372 # Ignore common stopwords
373 TAGGIT_STOPWORDS = [u'a', u'an', u'and', u'be', u'from', u'of']
374
375 ########## END TAGGIT CONFIGURATION
376