indexden is now optional
[oweals/karmaworld.git] / karmaworld / settings / prod.py
1 #!/usr/bin/env python
2 # -*- coding:utf8 -*-
3 # Copyright (C) 2012  FinalsClub Foundation
4 """ Production settings and globals. """
5 from os import environ
6 from datetime import timedelta
7 from S3 import CallingFormat
8
9 from common import *
10
11 ########## EMAIL CONFIGURATION
12 try:
13     # Include email is settings are there
14     # See: https://docs.djangoproject.com/en/dev/ref/settings/#email-host
15     EMAIL_HOST = os.environ['SMTP_HOST']
16
17     # See: https://docs.djangoproject.com/en/dev/ref/settings/#email-host-user
18     EMAIL_HOST_USER = os.environ['SMTP_USERNAME']
19
20     # See: https://docs.djangoproject.com/en/dev/ref/settings/#email-host-password
21     EMAIL_HOST_PASSWORD = os.environ['SMTP_PASSWORD']
22
23     # See: https://docs.djangoproject.com/en/dev/ref/settings/#email-backend
24     EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
25     
26     # See: https://docs.djangoproject.com/en/dev/ref/settings/#email-port
27     EMAIL_PORT = environ.get('EMAIL_PORT', 587)
28     
29     # See: https://docs.djangoproject.com/en/dev/ref/settings/#email-subject-prefix
30     EMAIL_SUBJECT_PREFIX = 'KarmaNotes '
31     
32     # See: https://docs.djangoproject.com/en/dev/ref/settings/#email-use-tls
33     EMAIL_USE_TLS = True
34     
35     DEFAULT_FROM_EMAIL = 'info@karmanotes.org'
36     
37     # See: https://docs.djangoproject.com/en/dev/ref/settings/#server-email
38     SERVER_EMAIL = EMAIL_HOST_USER
39
40     EMAIL = True
41
42 except:
43     EMAIL = False
44 ########## END EMAIL CONFIGURATION
45
46
47 ########## CACHE CONFIGURATION
48 # See: https://docs.djangoproject.com/en/dev/ref/settings/#caches
49 CACHES = {
50     'default': {
51         'BACKEND': 'django.core.cache.backends.memcached.PyLibMCCache',
52         'LOCATION': '127.0.0.1:11211'
53     }
54 }
55 ########## END CACHE CONFIGURATION
56
57
58 ########## CELERY CONFIGURATION
59 # See: http://docs.celeryproject.org/en/latest/configuration.html#broker-transport
60 BROKER_TRANSPORT = 'amqplib'
61
62 # Set this number to the amount of allowed concurrent connections on your AMQP
63 # provider, divided by the amount of active workers you have.
64 #
65 # For example, if you have the 'Little Lemur' CloudAMQP plan (their free tier),
66 # they allow 3 concurrent connections. So if you run a single worker, you'd
67 # want this number to be 3. If you had 3 workers running, you'd lower this
68 # number to 1, since 3 workers each maintaining one open connection = 3
69 # connections total.
70 #
71 # See: http://docs.celeryproject.org/en/latest/configuration.html#broker-pool-limit
72 # See: https://github.com/FinalsClub/karmaworld/issues/392
73 # See: http://stackoverflow.com/questions/23249850/celery-cloudamqp-creates-new-connection-for-each-task
74 # Basically, the broker pool causes too many connections!
75 BROKER_POOL_LIMIT = 0
76
77 # See: http://docs.celeryproject.org/en/latest/configuration.html#broker-connection-max-retries
78 #BROKER_CONNECTION_MAX_RETRIES = 0
79
80 # See: http://docs.celeryproject.org/en/latest/configuration.html#broker-url
81 BROKER_URL = environ.get('RABBITMQ_URL') or environ.get('CLOUDAMQP_URL')
82
83 # See: http://docs.celeryproject.org/en/latest/configuration.html#celery-result-backend
84 CELERY_RESULT_BACKEND = 'amqp'
85
86 # Periodic tasks
87 CELERYBEAT_SCHEDULE = {
88     'tweet-about-notes': {
89         'task': 'tweet_note',
90         'schedule': timedelta(minutes=60),
91     },
92     'check-mturk-results': {
93         'task': 'get_extract_keywords_results',
94         'schedule': timedelta(minutes=20),
95     },
96     'update-scoreboard': {
97         'task': 'fix_note_counts',
98         'schedule': timedelta(days=1),
99     },
100 }
101
102 CELERY_TIMEZONE = 'UTC'
103
104 ########## END CELERY CONFIGURATION
105
106
107 ########## STORAGE CONFIGURATION
108 # See: http://django-storages.readthedocs.org/en/latest/index.html
109 INSTALLED_APPS += (
110     'storages',
111     'gunicorn',
112 )
113
114 # See: http://django-storages.readthedocs.org/en/latest/backends/amazon-S3.html#settings
115 # DEFAULT_FILE_STORAGE comes from karmaworld.secret.static_s3
116 STATICFILES_STORAGE = DEFAULT_FILE_STORAGE
117
118 # Put static files in the folder 'static' in our S3 bucket.
119 # This is so they have the same path as they do when served
120 # locally for development.
121 AWS_LOCATION = 'static'
122
123 # See: http://django-storages.readthedocs.org/en/latest/backends/amazon-S3.html#settings
124 AWS_CALLING_FORMAT = CallingFormat.SUBDOMAIN
125
126 # AWS cache settings, don't change unless you know what you're doing:
127 AWS_EXPIREY = 60 * 60 * 24 * 7
128 AWS_HEADERS = {
129     'Cache-Control': 'max-age=%d, s-maxage=%d, must-revalidate' % (AWS_EXPIREY,
130         AWS_EXPIREY)
131 }
132
133 # See: https://docs.djangoproject.com/en/dev/ref/settings/#static-url
134 # S3_URL comes from karmaworld.secret.static_s3
135 STATIC_URL = '//' + os.environ['CLOUDFRONT_DOMAIN'] + '/' + AWS_LOCATION + '/'
136 ########## END STORAGE CONFIGURATION
137
138 ########## SSL FORWARDING CONFIGURATION
139 SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
140
141 if os.environ.get('SSL_REDIRECT', False) == 'true':
142     INSTALLED_APPS += ('sslify',)
143     MIDDLEWARE_CLASSES = (
144         'sslify.middleware.SSLifyMiddleware',
145     ) + MIDDLEWARE_CLASSES
146 ########## END SSL FORWARDING CONFIGURATION
147
148 ########## COMPRESSION CONFIGURATION
149 COMPRESS_ENABLED = True
150
151 # See: http://django_compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_OFFLINE
152 COMPRESS_OFFLINE = True
153
154 # See: http://django_compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_STORAGE
155 COMPRESS_STORAGE = os.environ.get('DEFAULT_FILE_STORAGE')
156
157 # Make sure that django-compressor serves from CloudFront
158 AWS_S3_CUSTOM_DOMAIN = os.environ.get('CLOUDFRONT_DOMAIN')
159
160 # See: http://django_compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_CSS_FILTERS
161 COMPRESS_CSS_FILTERS += [
162     'compressor.filters.datauri.CssDataUriFilter',
163     'compressor.filters.cssmin.CSSMinFilter',
164 ]
165 COMPRESS_DATA_URI_MAX_SIZE = 5120
166
167 # See: http://django_compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_JS_FILTERS
168 COMPRESS_JS_FILTERS += [
169     'compressor.filters.jsmin.JSMinFilter',
170 ]
171
172 # Links generated by compress are valid for about ten years
173 AWS_QUERYSTRING_EXPIRE = 60 * 60 * 24 * 365 * 10
174 ########## END COMPRESSION CONFIGURATION
175
176 ########## SECRET CONFIGURATION
177 # See: https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
178 SECRET_KEY = environ.get('SECRET_KEY', SECRET_KEY)
179 ########## END SECRET CONFIGURATION