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