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