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