dbf8be13f1006846851382c1aa341f1f300c45e5
[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     # Default Django middleware.
182     'django.middleware.common.CommonMiddleware',
183     'django.contrib.sessions.middleware.SessionMiddleware',
184     'django.middleware.csrf.CsrfViewMiddleware',
185     'django.contrib.auth.middleware.AuthenticationMiddleware',
186     'django.contrib.messages.middleware.MessageMiddleware',
187 )
188 ########## END MIDDLEWARE CONFIGURATION
189
190
191 ########## URL CONFIGURATION
192 # See: https://docs.djangoproject.com/en/dev/ref/settings/#root-urlconf
193 ROOT_URLCONF = '%s.urls' % SITE_NAME
194 ########## END URL CONFIGURATION
195
196
197 ########## APP CONFIGURATION
198 DJANGO_APPS = (
199     # Default Django apps:
200     'django.contrib.auth',
201     'django.contrib.contenttypes',
202     'django.contrib.sessions',
203     'django.contrib.sites',
204     'django.contrib.messages',
205     'django.contrib.staticfiles',
206
207     # Useful template tags:
208     'django.contrib.humanize',
209
210     # grappelli django-admin improvment, must be added before admin
211     'grappelli',
212
213     # Admin panel and documentation:
214     'django.contrib.admin',
215     'django.contrib.admindocs',
216 )
217
218 THIRD_PARTY_APPS = (
219     # Database migration helpers:
220     'south',
221
222     # Static file management:
223     'compressor',
224
225     # Asynchronous task queue:
226     'djcelery',
227
228     # Tagging https://github.com/yedpodtrzitko/django-taggit
229     'taggit',
230
231     'allauth',
232     'allauth.account',
233     'allauth.socialaccount',
234     # ... include the providers you want to enable:
235     'allauth.socialaccount.providers.facebook',
236     'allauth.socialaccount.providers.google',
237     'allauth.socialaccount.providers.twitter',
238 )
239
240 LOCAL_APPS = (
241     # file handling app
242     'karmaworld.apps.notes',
243     'karmaworld.apps.courses',
244     'karmaworld.apps.document_upload',
245     'karmaworld.apps.users',
246     'karmaworld.apps.moderation',
247     'karmaworld.apps.licenses',
248 )
249
250 # See: https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps
251 INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS
252 ########## END APP CONFIGURATION
253
254
255 ########## AUTHENTICATION
256
257 AUTHENTICATION_BACKENDS = (
258     # Needed to login by username in Django admin, regardless of `allauth`
259     "django.contrib.auth.backends.ModelBackend",
260
261     # `allauth` specific authentication methods, such as login by e-mail
262     "allauth.account.auth_backends.AuthenticationBackend",
263 )
264
265 ACCOUNT_EMAIL_REQUIRED = True
266 ACCOUNT_AUTHENTICATION_METHOD = "email"
267 ACCOUNT_CONFIRM_EMAIL_ON_GET = False
268 ACCOUNT_EMAIL_VERIFICATION = "optional"
269 ACCOUNT_EMAIL_SUBJECT_PREFIX = "KarmaNotes.org -- "
270 ACCOUNT_USERNAME_REQUIRED = True
271 SOCIALACCOUNT_EMAIL_REQUIRED = True
272 SOCIALACCOUNT_EMAIL_VERIFICATION = "optional"
273 SOCIALACCOUNT_QUERY_EMAIL = True
274 SOCIALACCOUNT_AUTO_SIGNUP = False
275 ACCOUNT_USER_DISPLAY = 'karmaworld.apps.users.models.user_display_name'
276 ACCOUNT_SIGNUP_FORM_CLASS = 'karmaworld.apps.users.forms.SignupForm'
277
278 AUTH_PROFILE_MODULE = 'users.UserProfile'
279
280 ######### END AUTHENTICATION
281
282 ########## LOGGING CONFIGURATION
283 # See: https://docs.djangoproject.com/en/dev/ref/settings/#logging
284 LOGGING = {
285     'version': 1,
286     'disable_existing_loggers': False,
287     'filters': {
288          'require_debug_false': {
289              '()': 'django.utils.log.RequireDebugFalse'
290          }
291      },
292     'handlers': {
293         'console': {
294             'level': 'INFO',
295             'class': 'logging.StreamHandler'
296         },
297         'mail_admins': {
298             'level': 'ERROR',
299             'filters': ['require_debug_false'],
300             'class': 'django.utils.log.AdminEmailHandler'
301         }
302     },
303     'loggers': {
304         'django': {
305             'handlers': ['console'],
306             'level': 'INFO'
307         },
308         'django.request': {
309             'handlers': ['mail_admins'],
310             'level': 'ERROR',
311             'propagate': True
312         },
313     }
314 }
315 ########## END LOGGING CONFIGURATION
316
317
318 ########## CELERY CONFIGURATION
319 # See: http://celery.readthedocs.org/en/latest/configuration.html#celery-task-result-expires
320 CELERY_TASK_RESULT_EXPIRES = timedelta(minutes=30)
321
322 # See: http://celery.github.com/celery/django/
323 setup_loader()
324 ########## END CELERY CONFIGURATION
325
326
327 ########## WSGI CONFIGURATION
328 # See: https://docs.djangoproject.com/en/dev/ref/settings/#wsgi-application
329 WSGI_APPLICATION = 'wsgi.application'
330 ########## END WSGI CONFIGURATION
331
332
333 ########## COMPRESSION CONFIGURATION
334 # See: http://django_compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_ENABLED
335 COMPRESS_ENABLED = True
336
337 # See: http://django_compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_CSS_FILTERS
338 COMPRESS_CSS_FILTERS = [
339     'compressor.filters.template.TemplateFilter',
340 ]
341
342 # See: http://django_compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_JS_FILTERS
343 COMPRESS_JS_FILTERS = [
344     'compressor.filters.template.TemplateFilter',
345 ]
346 ########## END COMPRESSION CONFIGURATION
347
348 ########## SESSION CONFIGURATION
349
350 SESSION_ENGINE = 'django.contrib.sessions.backends.db'
351 SESSION_COOKIE_AGE = 63072000    # 2 years in seconds
352
353 ########## END SESSION CONFIGURATION
354
355 ########## TAGGIT CONFIGURATION
356 # From https://github.com/yedpodtrzitko/django-taggit
357
358 # Use lowercase tags
359 TAGGIT_FORCE_LOWERCASE = True
360
361 # Ignore common stopwords
362 TAGGIT_STOPWORDS = [u'a', u'an', u'and', u'be', u'from', u'of']
363
364 ########## END TAGGIT CONFIGURATION
365