Make ssl redirection a separate config
[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 BROKER_POOL_LIMIT = 1
73
74 # See: http://docs.celeryproject.org/en/latest/configuration.html#broker-connection-max-retries
75 BROKER_CONNECTION_MAX_RETRIES = 0
76
77 # See: http://docs.celeryproject.org/en/latest/configuration.html#broker-url
78 BROKER_URL = environ.get('RABBITMQ_URL') or environ.get('CLOUDAMQP_URL')
79
80 # See: http://docs.celeryproject.org/en/latest/configuration.html#celery-result-backend
81 CELERY_RESULT_BACKEND = 'amqp'
82
83 # Periodic tasks
84 CELERYBEAT_SCHEDULE = {
85     'tweet-about-notes': {
86         'task': 'tweet_note',
87         'schedule': timedelta(minutes=60),
88     },
89     'check-mturk-results': {
90         'task': 'get_extract_keywords_results',
91         'schedule': timedelta(minutes=20),
92     },
93 }
94
95 CELERY_TIMEZONE = 'UTC'
96
97 ########## END CELERY CONFIGURATION
98
99
100 ########## STORAGE CONFIGURATION
101 # See: http://django-storages.readthedocs.org/en/latest/index.html
102 INSTALLED_APPS += (
103     'storages',
104     'gunicorn',
105 )
106
107 # See: http://django-storages.readthedocs.org/en/latest/backends/amazon-S3.html#settings
108 # DEFAULT_FILE_STORAGE comes from karmaworld.secret.static_s3
109 STATICFILES_STORAGE = DEFAULT_FILE_STORAGE
110
111 # Put static files in the folder 'static' in our S3 bucket.
112 # This is so they have the same path as they do when served
113 # locally for development.
114 AWS_LOCATION = 'static'
115
116 # See: http://django-storages.readthedocs.org/en/latest/backends/amazon-S3.html#settings
117 AWS_CALLING_FORMAT = CallingFormat.SUBDOMAIN
118
119 # AWS cache settings, don't change unless you know what you're doing:
120 AWS_EXPIREY = 60 * 60 * 24 * 7
121 AWS_HEADERS = {
122     'Cache-Control': 'max-age=%d, s-maxage=%d, must-revalidate' % (AWS_EXPIREY,
123         AWS_EXPIREY)
124 }
125
126 # See: https://docs.djangoproject.com/en/dev/ref/settings/#static-url
127 # S3_URL comes from karmaworld.secret.static_s3
128 STATIC_URL = '//' + os.environ['CLOUDFRONT_DOMAIN'] + '/' + AWS_LOCATION + '/'
129 ########## END STORAGE CONFIGURATION
130
131 ########## SSL FORWARDING CONFIGURATION
132 SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
133
134 if os.environ.get('SSL_REDIRECT', False) == 'true':
135     INSTALLED_APPS += ('sslify',)
136     MIDDLEWARE_CLASSES = (
137         'sslify.middleware.SSLifyMiddleware',
138     ) + MIDDLEWARE_CLASSES
139 ########## END SSL FORWARDING CONFIGURATION
140
141 ########## COMPRESSION CONFIGURATION
142 COMPRESS_ENABLED = True
143
144 # See: http://django_compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_OFFLINE
145 COMPRESS_OFFLINE = True
146
147 # See: http://django_compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_STORAGE
148 COMPRESS_STORAGE = os.environ.get('DEFAULT_FILE_STORAGE')
149
150 # Make sure that django-compressor serves from CloudFront
151 AWS_S3_CUSTOM_DOMAIN = os.environ.get('CLOUDFRONT_DOMAIN')
152
153 # See: http://django_compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_CSS_FILTERS
154 COMPRESS_CSS_FILTERS += [
155     'compressor.filters.datauri.CssDataUriFilter',
156     'compressor.filters.cssmin.CSSMinFilter',
157 ]
158 COMPRESS_DATA_URI_MAX_SIZE = 5120
159
160 # See: http://django_compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_JS_FILTERS
161 COMPRESS_JS_FILTERS += [
162     'compressor.filters.jsmin.JSMinFilter',
163 ]
164
165 # Links generated by compress are valid for about ten years
166 AWS_QUERYSTRING_EXPIRE = 60 * 60 * 24 * 365 * 10
167 ########## END COMPRESSION CONFIGURATION
168
169 ########## SECRET CONFIGURATION
170 # See: https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
171 SECRET_KEY = environ.get('SECRET_KEY', SECRET_KEY)
172 ########## END SECRET CONFIGURATION