Use mechanical turk to get keywords of notes
[oweals/karmaworld.git] / karmaworld / settings / vmdev.py
1 #!/usr/bin/env python
2 # -*- coding:utf8 -*-
3 # Copyright (C) 2012  FinalsClub Foundation
4 """ Production settings and globals. """
5
6
7 from os import environ
8 from datetime import timedelta
9 from S3 import CallingFormat
10
11 from common import *
12
13
14 from karmaworld.secret.static_s3 import *
15
16 from karmaworld.secret.db_settings import PROD_DB_NAME
17 from karmaworld.secret.db_settings import PROD_DB_USERNAME
18 from karmaworld.secret.db_settings import PROD_DB_PASSWORD
19
20 try:
21     # Include email is settings are there
22     from karmaworld.secret.email import SMTP_HOST
23     from karmaworld.secret.email import SMTP_USERNAME
24     from karmaworld.secret.email import SMTP_PASSWORD
25     EMAIL = True
26 except:
27     EMAIL = False
28
29 ########## EMAIL CONFIGURATION
30 if EMAIL:
31     # See: https://docs.djangoproject.com/en/dev/ref/settings/#email-backend
32     EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
33     
34     # See: https://docs.djangoproject.com/en/dev/ref/settings/#email-host
35     EMAIL_HOST = environ.get('EMAIL_HOST', SMTP_HOST)
36     
37     # See: https://docs.djangoproject.com/en/dev/ref/settings/#email-host-password
38     EMAIL_HOST_PASSWORD = environ.get('EMAIL_HOST_PASSWORD', SMTP_PASSWORD)
39     
40     # See: https://docs.djangoproject.com/en/dev/ref/settings/#email-host-user
41     EMAIL_HOST_USER = environ.get('EMAIL_HOST_USER', SMTP_USERNAME)
42     
43     # See: https://docs.djangoproject.com/en/dev/ref/settings/#email-port
44     EMAIL_PORT = environ.get('EMAIL_PORT', 587)
45     
46     # See: https://docs.djangoproject.com/en/dev/ref/settings/#email-subject-prefix
47     EMAIL_SUBJECT_PREFIX = 'KarmaNotes '
48     
49     # See: https://docs.djangoproject.com/en/dev/ref/settings/#email-use-tls
50     EMAIL_USE_TLS = True
51     
52     DEFAULT_FROM_EMAIL = 'info@karmanotes.org'
53     
54     # See: https://docs.djangoproject.com/en/dev/ref/settings/#server-email
55     SERVER_EMAIL = EMAIL_HOST_USER
56 ########## END EMAIL CONFIGURATION
57
58
59 ########## DATABASE CONFIGURATION
60 DATABASES = {
61     'default': {
62     'ENGINE': 'django.db.backends.postgresql_psycopg2',
63     'NAME': PROD_DB_NAME,
64     'USER': PROD_DB_USERNAME,
65     'PASSWORD': PROD_DB_PASSWORD,
66     'HOST': '',
67     'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
68     }
69 }
70 ########## END DATABASE CONFIGURATION
71
72
73 ########## CACHE CONFIGURATION
74 # See: https://docs.djangoproject.com/en/dev/ref/settings/#caches
75 CACHES = {
76     'default': {
77         'BACKEND': 'django.core.cache.backends.memcached.PyLibMCCache',
78     }
79 }
80 ########## END CACHE CONFIGURATION
81
82
83 ########## CELERY CONFIGURATION
84 # See: http://docs.celeryproject.org/en/latest/configuration.html#broker-transport
85 BROKER_TRANSPORT = 'amqplib'
86
87 # Set this number to the amount of allowed concurrent connections on your AMQP
88 # provider, divided by the amount of active workers you have.
89 #
90 # For example, if you have the 'Little Lemur' CloudAMQP plan (their free tier),
91 # they allow 3 concurrent connections. So if you run a single worker, you'd
92 # want this number to be 3. If you had 3 workers running, you'd lower this
93 # number to 1, since 3 workers each maintaining one open connection = 3
94 # connections total.
95 #
96 # See: http://docs.celeryproject.org/en/latest/configuration.html#broker-pool-limit
97 BROKER_POOL_LIMIT = 3
98
99 # See: http://docs.celeryproject.org/en/latest/configuration.html#broker-connection-max-retries
100 BROKER_CONNECTION_MAX_RETRIES = 0
101
102 # See: http://docs.celeryproject.org/en/latest/configuration.html#broker-url
103 BROKER_URL = environ.get('RABBITMQ_URL') or environ.get('CLOUDAMQP_URL')
104
105 # See: http://docs.celeryproject.org/en/latest/configuration.html#celery-result-backend
106 CELERY_RESULT_BACKEND = 'amqp'
107
108 # Periodic tasks
109 CELERYBEAT_SCHEDULE = {
110     'tweet-about-notes': {
111         'task': 'tweet_note',
112         'schedule': timedelta(minutes=60),
113     },
114 }
115
116 CELERY_TIMEZONE = 'UTC'
117
118 ########## END CELERY CONFIGURATION
119
120
121 ########## STORAGE CONFIGURATION
122 # See: http://django-storages.readthedocs.org/en/latest/index.html
123 INSTALLED_APPS += (
124     'storages',
125     'gunicorn',
126 )
127
128 # See: http://django-storages.readthedocs.org/en/latest/backends/amazon-S3.html#settings
129 STATICFILES_STORAGE = DEFAULT_FILE_STORAGE
130
131 # See: http://django-storages.readthedocs.org/en/latest/backends/amazon-S3.html#settings
132 AWS_CALLING_FORMAT = CallingFormat.SUBDOMAIN
133
134 # Put static files in the folder 'static' in our S3 bucket.
135 # This is so they have the same path as they do when served
136 # locally for development.
137 AWS_LOCATION = 'static'
138
139 # AWS cache settings, don't change unless you know what you're doing:
140 AWS_EXPIREY = 60 * 60 * 24 * 7
141 AWS_HEADERS = {
142     'Cache-Control': 'max-age=%d, s-maxage=%d, must-revalidate' % (AWS_EXPIREY,
143         AWS_EXPIREY)
144 }
145
146 # See: https://docs.djangoproject.com/en/dev/ref/settings/#static-url
147 STATIC_URL = CLOUDFRONT_URL + AWS_LOCATION + '/'
148 ########## END STORAGE CONFIGURATION
149
150
151 ########## SSL FORWARDING CONFIGURATION
152 SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
153 ########## END SSL FORWARDING CONFIGURATION
154
155
156 ########## COMPRESSION CONFIGURATION
157 # See: http://django_compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_OFFLINE
158 COMPRESS_OFFLINE = True
159
160 # See: http://django_compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_STORAGE
161 COMPRESS_STORAGE = DEFAULT_FILE_STORAGE
162
163 # Make sure that django-compressor serves from CloudFront
164 AWS_S3_CUSTOM_DOMAIN = CLOUDFRONT_DOMAIN
165
166 # See: http://django_compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_CSS_FILTERS
167 COMPRESS_CSS_FILTERS += [
168     'compressor.filters.datauri.CssDataUriFilter',
169     'compressor.filters.cssmin.CSSMinFilter',
170 ]
171 COMPRESS_DATA_URI_MAX_SIZE = 5120
172
173 # See: http://django_compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_JS_FILTERS
174 COMPRESS_JS_FILTERS += [
175     'compressor.filters.closure.ClosureCompilerFilter',
176 ]
177 COMPRESS_CLOSURE_COMPILER_BINARY = 'java -jar /usr/bin/compiler.jar'
178
179 # Links generated by compress are valid for about ten years
180 AWS_QUERYSTRING_EXPIRE = 60 * 60 * 24 * 365 * 10
181 ########## END COMPRESSION CONFIGURATION
182
183
184 ########## SECRET CONFIGURATION
185 # See: https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
186 SECRET_KEY = environ.get('SECRET_KEY', SECRET_KEY)
187 ########## END SECRET CONFIGURATION
188
189 ########## DEBUG CONFIGURATION
190 # See: https://docs.djangoproject.com/en/dev/ref/settings/#debug
191 DEBUG = True
192
193 # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-debug
194 TEMPLATE_DEBUG = DEBUG
195 ########## END DEBUG CONFIGURATION
196
197 ########## TESTING CONFIGURATION
198 # Use django-nose to test our app, see https://github.com/jbalogh/django-nose
199 TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
200 ########## END TESTING CONFIGURATION
201
202 ########## TOOLBAR CONFIGURATION
203 # See: https://github.com/django-debug-toolbar/django-debug-toolbar#installation
204 INSTALLED_APPS += (
205     'debug_toolbar',
206     'django_extensions',
207     'django_nose',
208 )
209
210 DEBUG_TOOLBAR_PANELS = (
211     'debug_toolbar.panels.versions.VersionsPanel',
212     'debug_toolbar.panels.timer.TimerPanel',
213     'debug_toolbar.panels.settings.SettingsPanel',
214     'debug_toolbar.panels.headers.HeadersPanel',
215     'debug_toolbar.panels.request.RequestPanel',
216     'debug_toolbar.panels.sql.SQLPanel',
217     'debug_toolbar.panels.staticfiles.StaticFilesPanel',
218     'debug_toolbar.panels.templates.TemplatesPanel',
219     'debug_toolbar.panels.cache.CachePanel',
220     'debug_toolbar.panels.signals.SignalsPanel',
221     'debug_toolbar.panels.logging.LoggingPanel',
222 )
223
224 # See: https://github.com/django-debug-toolbar/django-debug-toolbar#installation
225 INTERNAL_IPS = ('127.0.0.1',)
226
227 # See: https://github.com/django-debug-toolbar/django-debug-toolbar#installation
228 MIDDLEWARE_CLASSES += (
229     'debug_toolbar.middleware.DebugToolbarMiddleware',
230 )
231 ########## END TOOLBAR CONFIGURATION
232
233 ########## PROFILING CONFIGURATION
234 MIDDLEWARE_CLASSES += (
235     'karmaworld.apps.courses.middleware.ProfileMiddleware',
236 )
237 ########## END PROFILING CONFIGURATION
238
239 ########## STATIC CONFIGURATION
240 STATIC_URL = CLOUDFRONT_URL
241 ########## END STATIC CONFIGURATION