3 # Copyright (C) 2012 FinalsClub Foundation
4 """ Production settings and globals. """
6 from datetime import timedelta
7 from S3 import CallingFormat
11 ########## EMAIL CONFIGURATION
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']
17 # See: https://docs.djangoproject.com/en/dev/ref/settings/#email-host-user
18 EMAIL_HOST_USER = os.environ['SMTP_USERNAME']
20 # See: https://docs.djangoproject.com/en/dev/ref/settings/#email-host-password
21 EMAIL_HOST_PASSWORD = os.environ['SMTP_PASSWORD']
23 # See: https://docs.djangoproject.com/en/dev/ref/settings/#email-backend
24 EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
26 # See: https://docs.djangoproject.com/en/dev/ref/settings/#email-port
27 EMAIL_PORT = environ.get('EMAIL_PORT', 587)
29 # See: https://docs.djangoproject.com/en/dev/ref/settings/#email-subject-prefix
30 EMAIL_SUBJECT_PREFIX = 'KarmaNotes '
32 # See: https://docs.djangoproject.com/en/dev/ref/settings/#email-use-tls
35 DEFAULT_FROM_EMAIL = 'info@karmanotes.org'
37 # See: https://docs.djangoproject.com/en/dev/ref/settings/#server-email
38 SERVER_EMAIL = EMAIL_HOST_USER
44 ########## END EMAIL CONFIGURATION
47 ########## CACHE CONFIGURATION
48 # See: https://docs.djangoproject.com/en/dev/ref/settings/#caches
51 'BACKEND': 'django.core.cache.backends.memcached.PyLibMCCache',
52 'LOCATION': '127.0.0.1:11211'
55 ########## END CACHE CONFIGURATION
58 ########## CELERY CONFIGURATION
59 # See: http://docs.celeryproject.org/en/latest/configuration.html#broker-transport
60 BROKER_TRANSPORT = 'amqplib'
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.
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
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!
77 # See: http://docs.celeryproject.org/en/latest/configuration.html#broker-connection-max-retries
78 #BROKER_CONNECTION_MAX_RETRIES = 0
80 # See: http://docs.celeryproject.org/en/latest/configuration.html#broker-url
81 BROKER_URL = environ.get('RABBITMQ_URL') or environ.get('CLOUDAMQP_URL')
83 # See: http://docs.celeryproject.org/en/latest/configuration.html#celery-result-backend
84 CELERY_RESULT_BACKEND = 'amqp'
87 CELERYBEAT_SCHEDULE = {
88 'tweet-about-notes': {
90 'schedule': timedelta(minutes=60),
92 'check-mturk-results': {
93 'task': 'get_extract_keywords_results',
94 'schedule': timedelta(minutes=20),
96 'update-scoreboard': {
97 'task': 'fix_note_counts',
98 'schedule': timedelta(days=1),
102 CELERY_TIMEZONE = 'UTC'
104 ########## END CELERY CONFIGURATION
107 ########## STORAGE CONFIGURATION
108 # See: http://django-storages.readthedocs.org/en/latest/index.html
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
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'
123 # See: http://django-storages.readthedocs.org/en/latest/backends/amazon-S3.html#settings
124 AWS_CALLING_FORMAT = CallingFormat.SUBDOMAIN
126 # AWS cache settings, don't change unless you know what you're doing:
127 AWS_EXPIREY = 60 * 60 * 24 * 7
129 'Cache-Control': 'max-age=%d, s-maxage=%d, must-revalidate' % (AWS_EXPIREY,
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
138 ########## SSL FORWARDING CONFIGURATION
139 SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
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
148 ########## COMPRESSION CONFIGURATION
149 COMPRESS_ENABLED = True
151 # See: http://django_compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_OFFLINE
152 COMPRESS_OFFLINE = True
154 # See: http://django_compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_STORAGE
155 COMPRESS_STORAGE = os.environ.get('DEFAULT_FILE_STORAGE')
157 # Make sure that django-compressor serves from CloudFront
158 AWS_S3_CUSTOM_DOMAIN = os.environ.get('CLOUDFRONT_DOMAIN')
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',
165 COMPRESS_DATA_URI_MAX_SIZE = 5120
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',
172 # Links generated by compress are valid for about ten years
173 AWS_QUERYSTRING_EXPIRE = 60 * 60 * 24 * 365 * 10
174 ########## END COMPRESSION CONFIGURATION
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