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