2016-12-09 05:11:31 +00:00
|
|
|
import os
|
|
|
|
import dj_database_url
|
|
|
|
|
|
|
|
from .base import *
|
|
|
|
|
|
|
|
# Do not set SECRET_KEY, Postgres or LDAP password or any other sensitive data here.
|
|
|
|
# Instead, use environment variables or create a local.py file on the server.
|
|
|
|
|
|
|
|
# Disable debug mode
|
2017-03-28 22:49:05 +00:00
|
|
|
DEBUG = False
|
|
|
|
TEMPLATES[0]['OPTIONS']['debug'] = False
|
2016-12-09 05:11:31 +00:00
|
|
|
|
|
|
|
# Compress static files offline and minify CSS
|
|
|
|
# http://django-compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_OFFLINE
|
|
|
|
COMPRESS_OFFLINE = True
|
|
|
|
COMPRESS_CSS_FILTERS = [
|
|
|
|
'compressor.filters.css_default.CssAbsoluteFilter',
|
|
|
|
'compressor.filters.cssmin.CSSMinFilter',
|
|
|
|
]
|
|
|
|
COMPRESS_CSS_HASHING_METHOD = 'content'
|
|
|
|
|
|
|
|
|
|
|
|
# Configuration from environment variables
|
|
|
|
# Alternatively, you can set these in a local.py file on the server
|
|
|
|
|
|
|
|
env = os.environ.copy()
|
|
|
|
|
|
|
|
# On Torchbox servers, many environment variables are prefixed with "CFG_"
|
|
|
|
for key, value in os.environ.items():
|
|
|
|
if key.startswith('CFG_'):
|
|
|
|
env[key[4:]] = value
|
|
|
|
|
|
|
|
|
|
|
|
# Basic configuration
|
|
|
|
|
2016-12-09 05:13:01 +00:00
|
|
|
APP_NAME = env.get('APP_NAME', 'publichealth')
|
2016-12-09 05:11:31 +00:00
|
|
|
|
|
|
|
if 'SECRET_KEY' in env:
|
|
|
|
SECRET_KEY = env['SECRET_KEY']
|
|
|
|
|
|
|
|
if 'ALLOWED_HOSTS' in env:
|
|
|
|
ALLOWED_HOSTS = env['ALLOWED_HOSTS'].split(',')
|
|
|
|
|
|
|
|
if 'PRIMARY_HOST' in env:
|
|
|
|
BASE_URL = 'http://%s/' % env['PRIMARY_HOST']
|
|
|
|
|
|
|
|
if 'SERVER_EMAIL' in env:
|
|
|
|
SERVER_EMAIL = env['SERVER_EMAIL']
|
|
|
|
|
|
|
|
if 'CACHE_PURGE_URL' in env:
|
|
|
|
INSTALLED_APPS += ( 'wagtail.contrib.wagtailfrontendcache', )
|
|
|
|
WAGTAILFRONTENDCACHE = {
|
|
|
|
'default': {
|
|
|
|
'BACKEND': 'wagtail.contrib.wagtailfrontendcache.backends.HTTPBackend',
|
|
|
|
'LOCATION': env['CACHE_PURGE_URL'],
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
if 'STATIC_URL' in env:
|
|
|
|
STATIC_URL = env['STATIC_URL']
|
|
|
|
|
|
|
|
if 'STATIC_DIR' in env:
|
|
|
|
STATIC_ROOT = env['STATIC_DIR']
|
|
|
|
|
|
|
|
if 'MEDIA_URL' in env:
|
|
|
|
MEDIA_URL = env['MEDIA_URL']
|
|
|
|
|
|
|
|
if 'MEDIA_DIR' in env:
|
|
|
|
MEDIA_ROOT = env['MEDIA_DIR']
|
|
|
|
|
|
|
|
|
|
|
|
# Database
|
|
|
|
|
|
|
|
if 'DATABASE_URL' in os.environ:
|
|
|
|
DATABASES = {'default': dj_database_url.config()}
|
|
|
|
|
|
|
|
else:
|
|
|
|
DATABASES = {
|
|
|
|
'default': {
|
|
|
|
'ENGINE': 'django.db.backends.postgresql_psycopg2',
|
|
|
|
'NAME': env.get('PGDATABASE', APP_NAME),
|
|
|
|
'CONN_MAX_AGE': 600, # number of seconds database connections should persist for
|
|
|
|
|
|
|
|
# User, host and port can be configured by the PGUSER, PGHOST and
|
|
|
|
# PGPORT environment variables (these get picked up by libpq).
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-04-05 21:50:38 +00:00
|
|
|
# Email via ESP
|
|
|
|
|
|
|
|
if 'MAILGUN_KEY' in os.environ:
|
|
|
|
EMAIL_BACKEND = "anymail.backends.mailgun.EmailBackend"
|
|
|
|
ANYMAIL = {
|
|
|
|
"MAILGUN_API_KEY": env['MAILGUN_KEY'],
|
|
|
|
"MAILGUN_SENDER_DOMAIN": env['MAILGUN_DOMAIN']
|
|
|
|
}
|
|
|
|
DEFAULT_FROM_EMAIL = env['MAILGUN_FROM']
|
|
|
|
|
2017-04-10 22:51:40 +00:00
|
|
|
# Use Redis as the cache backend for extra performance
|
|
|
|
|
|
|
|
CACHES = {
|
|
|
|
'default': {
|
|
|
|
'BACKEND': 'django_redis.cache.RedisCache',
|
|
|
|
'LOCATION': '127.0.0.1:6379',
|
|
|
|
'KEY_PREFIX': 'publichealth',
|
|
|
|
'OPTIONS': {
|
|
|
|
'CLIENT_CLASS': 'django_redis.client.DefaultClient',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-09 05:11:31 +00:00
|
|
|
# Redis location can either be passed through with REDIS_HOST or REDIS_SOCKET
|
|
|
|
|
|
|
|
if 'REDIS_URL' in env:
|
|
|
|
REDIS_LOCATION = env['REDIS_URL']
|
|
|
|
BROKER_URL = env['REDIS_URL']
|
|
|
|
|
|
|
|
elif 'REDIS_HOST' in env:
|
|
|
|
REDIS_LOCATION = env['REDIS_HOST']
|
|
|
|
BROKER_URL = 'redis://%s' % env['REDIS_HOST']
|
|
|
|
|
|
|
|
elif 'REDIS_SOCKET' in env:
|
|
|
|
REDIS_LOCATION = 'unix://%s' % env['REDIS_SOCKET']
|
|
|
|
BROKER_URL = 'redis+socket://%s' % env['REDIS_SOCKET']
|
|
|
|
|
|
|
|
else:
|
|
|
|
REDIS_LOCATION = None
|
|
|
|
|
|
|
|
|
|
|
|
if REDIS_LOCATION is not None:
|
|
|
|
CACHES = {
|
|
|
|
'default': {
|
|
|
|
'BACKEND': 'django_redis.cache.RedisCache',
|
|
|
|
'LOCATION': REDIS_LOCATION,
|
|
|
|
'KEY_PREFIX': APP_NAME,
|
|
|
|
'OPTIONS': {
|
|
|
|
'CLIENT_CLASS': 'django_redis.client.DefaultClient',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-10 22:51:40 +00:00
|
|
|
# Use Elasticsearch as the search backend for extra performance and better search results
|
2016-12-09 05:11:31 +00:00
|
|
|
|
|
|
|
if 'ELASTICSEARCH_URL' in env:
|
|
|
|
WAGTAILSEARCH_BACKENDS = {
|
|
|
|
'default': {
|
2017-04-06 07:42:47 +00:00
|
|
|
'BACKEND': 'wagtail.wagtailsearch.backends.elasticsearch5',
|
2016-12-09 05:11:31 +00:00
|
|
|
'URLS': [env['ELASTICSEARCH_URL']],
|
|
|
|
'INDEX': APP_NAME,
|
|
|
|
'ATOMIC_REBUILD': True,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Logging
|
|
|
|
|
|
|
|
LOGGING = {
|
|
|
|
'version': 1,
|
|
|
|
'disable_existing_loggers': False,
|
|
|
|
'handlers': {
|
|
|
|
'mail_admins': {
|
|
|
|
'level': 'ERROR',
|
|
|
|
'class': 'django.utils.log.AdminEmailHandler',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'formatters': {
|
|
|
|
'default': {
|
|
|
|
'verbose': '[%(asctime)s] (%(process)d/%(thread)d) %(name)s %(levelname)s: %(message)s'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'loggers': {
|
2016-12-09 05:13:01 +00:00
|
|
|
'publichealth': {
|
2016-12-09 05:11:31 +00:00
|
|
|
'handlers': [],
|
|
|
|
'level': 'INFO',
|
|
|
|
'propagate': False,
|
|
|
|
'formatter': 'verbose',
|
|
|
|
},
|
|
|
|
'wagtail': {
|
|
|
|
'handlers': [],
|
|
|
|
'level': 'INFO',
|
|
|
|
'propagate': False,
|
|
|
|
'formatter': 'verbose',
|
|
|
|
},
|
|
|
|
'django.request': {
|
|
|
|
'handlers': ['mail_admins'],
|
|
|
|
'level': 'ERROR',
|
|
|
|
'propagate': False,
|
|
|
|
'formatter': 'verbose',
|
|
|
|
},
|
|
|
|
'django.security': {
|
|
|
|
'handlers': ['mail_admins'],
|
|
|
|
'level': 'ERROR',
|
|
|
|
'propagate': False,
|
|
|
|
'formatter': 'verbose',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if 'LOG_DIR' in env:
|
|
|
|
# Public Health Schweiz log
|
2016-12-09 05:13:01 +00:00
|
|
|
LOGGING['handlers']['publichealth_file'] = {
|
2016-12-09 05:11:31 +00:00
|
|
|
'level': 'INFO',
|
|
|
|
'class': 'cloghandler.ConcurrentRotatingFileHandler',
|
2016-12-09 05:13:01 +00:00
|
|
|
'filename': os.path.join(env['LOG_DIR'], 'publichealth.log'),
|
2016-12-09 05:11:31 +00:00
|
|
|
'maxBytes': 5242880, # 5MB
|
|
|
|
'backupCount': 5
|
|
|
|
}
|
2016-12-09 05:13:01 +00:00
|
|
|
LOGGING['loggers']['wagtail']['handlers'].append('publichealth_file')
|
2016-12-09 05:11:31 +00:00
|
|
|
|
|
|
|
# Wagtail log
|
|
|
|
LOGGING['handlers']['wagtail_file'] = {
|
|
|
|
'level': 'INFO',
|
|
|
|
'class': 'cloghandler.ConcurrentRotatingFileHandler',
|
|
|
|
'filename': os.path.join(env['LOG_DIR'], 'wagtail.log'),
|
|
|
|
'maxBytes': 5242880, # 5MB
|
|
|
|
'backupCount': 5
|
|
|
|
}
|
|
|
|
LOGGING['loggers']['wagtail']['handlers'].append('wagtail_file')
|
|
|
|
|
|
|
|
# Error log
|
|
|
|
LOGGING['handlers']['errors_file'] = {
|
|
|
|
'level': 'ERROR',
|
|
|
|
'class': 'cloghandler.ConcurrentRotatingFileHandler',
|
|
|
|
'filename': os.path.join(env['LOG_DIR'], 'error.log'),
|
|
|
|
'maxBytes': 5242880, # 5MB
|
|
|
|
'backupCount': 5
|
|
|
|
}
|
|
|
|
LOGGING['loggers']['django.request']['handlers'].append('errors_file')
|
|
|
|
LOGGING['loggers']['django.security']['handlers'].append('errors_file')
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
from .local import *
|
|
|
|
except ImportError:
|
|
|
|
pass
|