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