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