Merge branch 'master' into quizzes
[oweals/karmaworld.git] / karmaworld / settings / vmdev.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 *
15
16 from karmaworld.secret.db_settings import PROD_DB_NAME
17 from karmaworld.secret.db_settings import PROD_DB_USERNAME
18 from karmaworld.secret.db_settings import PROD_DB_PASSWORD
19
20 try:
21     # Include email is settings are there
22     from karmaworld.secret.email import SMTP_HOST
23     from karmaworld.secret.email import SMTP_USERNAME
24     from karmaworld.secret.email import SMTP_PASSWORD
25     EMAIL = True
26 except:
27     EMAIL = False
28
29 ########## EMAIL CONFIGURATION
30 if EMAIL:
31     # See: https://docs.djangoproject.com/en/dev/ref/settings/#email-backend
32     EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
33     
34     # See: https://docs.djangoproject.com/en/dev/ref/settings/#email-host
35     EMAIL_HOST = environ.get('EMAIL_HOST', SMTP_HOST)
36     
37     # See: https://docs.djangoproject.com/en/dev/ref/settings/#email-host-password
38     EMAIL_HOST_PASSWORD = environ.get('EMAIL_HOST_PASSWORD', SMTP_PASSWORD)
39     
40     # See: https://docs.djangoproject.com/en/dev/ref/settings/#email-host-user
41     EMAIL_HOST_USER = environ.get('EMAIL_HOST_USER', SMTP_USERNAME)
42     
43     # See: https://docs.djangoproject.com/en/dev/ref/settings/#email-port
44     EMAIL_PORT = environ.get('EMAIL_PORT', 587)
45     
46     # See: https://docs.djangoproject.com/en/dev/ref/settings/#email-subject-prefix
47     EMAIL_SUBJECT_PREFIX = 'KarmaNotes '
48     
49     # See: https://docs.djangoproject.com/en/dev/ref/settings/#email-use-tls
50     EMAIL_USE_TLS = True
51     
52     DEFAULT_FROM_EMAIL = 'info@karmanotes.org'
53     
54     # See: https://docs.djangoproject.com/en/dev/ref/settings/#server-email
55     SERVER_EMAIL = EMAIL_HOST_USER
56 ########## END EMAIL CONFIGURATION
57
58
59 ########## DATABASE CONFIGURATION
60 DATABASES = {
61     'default': {
62     'ENGINE': 'django.db.backends.postgresql_psycopg2',
63     'NAME': PROD_DB_NAME,
64     'USER': PROD_DB_USERNAME,
65     'PASSWORD': PROD_DB_PASSWORD,
66     'HOST': '',
67     'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
68     }
69 }
70 ########## END DATABASE CONFIGURATION
71
72
73 ########## CACHE CONFIGURATION
74 # See: https://docs.djangoproject.com/en/dev/ref/settings/#caches
75 CACHES = {
76     'default': {
77         'BACKEND': 'django.core.cache.backends.memcached.PyLibMCCache',
78     }
79 }
80 ########## END CACHE CONFIGURATION
81
82
83 ########## CELERY CONFIGURATION
84 # See: http://docs.celeryproject.org/en/latest/configuration.html#broker-transport
85 BROKER_TRANSPORT = 'amqplib'
86
87 # Set this number to the amount of allowed concurrent connections on your AMQP
88 # provider, divided by the amount of active workers you have.
89 #
90 # For example, if you have the 'Little Lemur' CloudAMQP plan (their free tier),
91 # they allow 3 concurrent connections. So if you run a single worker, you'd
92 # want this number to be 3. If you had 3 workers running, you'd lower this
93 # number to 1, since 3 workers each maintaining one open connection = 3
94 # connections total.
95 #
96 # See: http://docs.celeryproject.org/en/latest/configuration.html#broker-pool-limit
97 BROKER_POOL_LIMIT = 3
98
99 # See: http://docs.celeryproject.org/en/latest/configuration.html#broker-connection-max-retries
100 BROKER_CONNECTION_MAX_RETRIES = 0
101
102 # See: http://docs.celeryproject.org/en/latest/configuration.html#broker-url
103 BROKER_URL = environ.get('RABBITMQ_URL') or environ.get('CLOUDAMQP_URL')
104
105 # See: http://docs.celeryproject.org/en/latest/configuration.html#celery-result-backend
106 CELERY_RESULT_BACKEND = 'amqp'
107
108 # Periodic tasks
109 CELERYBEAT_SCHEDULE = {
110     'tweet-about-notes': {
111         'task': 'tweet_note',
112         'schedule': timedelta(minutes=60),
113     },
114 }
115
116 CELERY_TIMEZONE = 'UTC'
117
118 ########## END CELERY CONFIGURATION
119
120
121 ########## STORAGE CONFIGURATION
122 # See: http://django-storages.readthedocs.org/en/latest/index.html
123 INSTALLED_APPS += (
124     'storages',
125     'gunicorn',
126 )
127
128 # See: http://django-storages.readthedocs.org/en/latest/backends/amazon-S3.html#settings
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
135 # AWS cache settings, don't change unless you know what you're doing:
136 AWS_EXPIREY = 60 * 60 * 24 * 7
137 AWS_HEADERS = {
138     'Cache-Control': 'max-age=%d, s-maxage=%d, must-revalidate' % (AWS_EXPIREY,
139         AWS_EXPIREY)
140 }
141
142 # See: https://docs.djangoproject.com/en/dev/ref/settings/#static-url
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
170
171 ########## DEBUG CONFIGURATION
172 # See: https://docs.djangoproject.com/en/dev/ref/settings/#debug
173 DEBUG = True
174
175 # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-debug
176 TEMPLATE_DEBUG = DEBUG
177 ########## END DEBUG CONFIGURATION
178
179 ########## TESTING CONFIGURATION
180 # Use django-nose to test our app, see https://github.com/jbalogh/django-nose
181 TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
182 ########## END TESTING CONFIGURATION
183
184 ########## TOOLBAR CONFIGURATION
185 # See: https://github.com/django-debug-toolbar/django-debug-toolbar#installation
186 INSTALLED_APPS += (
187     'debug_toolbar',
188     'django_extensions',
189     'django_nose',
190 )
191
192 # See: https://github.com/django-debug-toolbar/django-debug-toolbar#installation
193 INTERNAL_IPS = ('127.0.0.1',)
194
195 # See: https://github.com/django-debug-toolbar/django-debug-toolbar#installation
196 MIDDLEWARE_CLASSES += (
197     'debug_toolbar.middleware.DebugToolbarMiddleware',
198 )
199
200 DEBUG_TOOLBAR_CONFIG = {
201     'INTERCEPT_REDIRECTS': False # Don't interrput our redirects!
202 }
203 ########## END TOOLBAR CONFIGURATION