1
0
Fork 0
satnogs-db/db/settings.py

277 lines
7.9 KiB
Python
Raw Normal View History

2018-01-06 04:25:23 -07:00
from decouple import config, Csv
from dj_database_url import parse as db_url
from unipath import Path
2016-05-06 11:19:02 -06:00
ROOT = Path(__file__).parent
2015-04-22 05:05:30 -06:00
2018-01-06 04:25:23 -07:00
ENVIRONMENT = config('ENVIRONMENT', default='production')
DEBUG = config('DEBUG', default=False, cast=bool)
2017-05-08 08:29:56 -06:00
2015-04-22 05:05:30 -06:00
# Apps
DJANGO_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
)
THIRD_PARTY_APPS = (
2017-03-02 10:55:10 -07:00
'avatar',
2015-04-22 05:05:30 -06:00
'rest_framework',
2017-03-02 10:55:10 -07:00
'rest_framework.authtoken',
'django_filters',
2015-04-22 05:05:30 -06:00
'allauth',
'allauth.account',
'crispy_forms',
2015-09-15 04:32:07 -06:00
'compressor',
2017-02-21 10:22:39 -07:00
'csp',
2015-04-22 05:05:30 -06:00
)
LOCAL_APPS = (
'db.base',
'db.api',
)
INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS
# Middlware
MIDDLEWARE = (
2015-04-22 05:05:30 -06:00
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
2017-02-21 10:22:39 -07:00
'csp.middleware.CSPMiddleware',
2015-04-22 05:05:30 -06:00
)
# Email
2017-05-08 08:29:56 -06:00
if DEBUG:
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
else:
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'localhost'
EMAIL_PORT = 25
EMAIL_TIMEOUT = 300
2018-01-06 04:25:23 -07:00
DEFAULT_FROM_EMAIL = config('DEFAULT_FROM_EMAIL', default='noreply@satnogs.org')
ADMINS = [
('SatNOGS Admins', DEFAULT_FROM_EMAIL)
]
2015-04-22 05:05:30 -06:00
MANAGERS = ADMINS
2017-05-08 08:29:56 -06:00
SERVER_EMAIL = DEFAULT_FROM_EMAIL
2015-04-22 05:05:30 -06:00
# Cache
CACHES = {
'default': {
2018-01-06 04:25:23 -07:00
'BACKEND': config('CACHE_BACKEND', default='redis_cache.RedisCache'),
'LOCATION': config('CACHE_LOCATION', default='unix://var/run/redis/redis.sock'),
2017-05-08 08:29:56 -06:00
'OPTIONS': {
2018-01-06 04:25:23 -07:00
'CLIENT_CLASS': config('CACHE_CLIENT_CLASS',
default='django_redis.client.DefaultClient'),
2017-05-08 08:29:56 -06:00
},
'KEY_PREFIX': 'db-{0}'.format(ENVIRONMENT),
2015-04-22 05:05:30 -06:00
}
}
2018-01-06 04:25:23 -07:00
CACHE_TTL = config('CACHE_TTL', default=300, cast=int)
2015-04-22 05:05:30 -06:00
# Internationalization
TIME_ZONE = 'UTC'
LANGUAGE_CODE = 'en-us'
SITE_ID = 1
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Templates
2016-02-03 13:14:07 -07:00
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
Path(ROOT).child('templates').resolve(),
],
2016-02-03 13:14:07 -07:00
'OPTIONS': {
'context_processors': [
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.debug',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages',
'django.template.context_processors.request',
'db.base.context_processors.analytics',
'db.base.context_processors.stage_notice',
],
'loaders': [
2017-11-13 03:30:39 -07:00
('django.template.loaders.cached.Loader', [
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
]),
2016-02-03 13:14:07 -07:00
],
},
2016-02-03 13:14:07 -07:00
},
]
2015-04-22 05:05:30 -06:00
# Static & Media
STATIC_ROOT = Path('staticfiles').resolve()
2015-04-22 05:05:30 -06:00
STATIC_URL = '/static/'
STATICFILES_DIRS = [
Path(ROOT).child('static').resolve(),
]
2015-04-22 05:05:30 -06:00
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
2015-09-15 04:32:07 -06:00
'compressor.finders.CompressorFinder',
2015-04-22 05:05:30 -06:00
)
MEDIA_ROOT = Path('media').resolve()
2015-04-22 05:05:30 -06:00
MEDIA_URL = '/media/'
CRISPY_TEMPLATE_PACK = 'bootstrap3'
SATELLITE_DEFAULT_IMAGE = '/static/img/sat.png'
2018-01-06 04:25:23 -07:00
COMPRESS_ENABLED = config('COMPRESS_ENABLED', default=False, cast=bool)
COMPRESS_OFFLINE = config('COMPRESS_OFFLINE', default=False, cast=bool)
COMPRESS_CACHE_BACKEND = config('COMPRESS_CACHE_BACKEND', default='default')
COMPRESS_CSS_FILTERS = [
'compressor.filters.css_default.CssAbsoluteFilter',
'compressor.filters.cssmin.rCSSMinFilter'
]
2015-04-22 05:05:30 -06:00
# App conf
ROOT_URLCONF = 'db.urls'
WSGI_APPLICATION = 'db.wsgi.application'
# Auth
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
'allauth.account.auth_backends.AuthenticationBackend',
)
ACCOUNT_AUTHENTICATION_METHOD = 'username'
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_EMAIL_VERIFICATION = 'mandatory'
LOGIN_REDIRECT_URL = 'home'
# Logging
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
2015-07-17 11:22:07 -06:00
'formatters': {
'verbose': {
2015-07-17 11:59:23 -06:00
'format': '%(levelname)s %(asctime)s %(module)s - %(process)d %(thread)d - %(message)s'
2015-07-17 11:22:07 -06:00
},
},
2015-04-22 05:05:30 -06:00
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'handlers': {
2015-07-17 11:22:07 -06:00
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'verbose'
},
2015-04-22 05:05:30 -06:00
},
'loggers': {
'django.request': {
'level': 'ERROR',
'handlers': ['console'],
2015-09-17 05:33:13 -06:00
'propagate': False,
2015-04-22 05:05:30 -06:00
},
2015-07-17 11:22:07 -06:00
'django.db.backends': {
'level': 'ERROR',
'handlers': ['console'],
2015-07-17 11:22:07 -06:00
'propagate': False,
},
'db': {
'level': 'WARNING',
'handlers': ['console'],
'propagate': False,
},
2015-04-22 05:05:30 -06:00
}
}
# Celery
CELERY_ENABLE_UTC = USE_TZ
CELERY_TIMEZONE = TIME_ZONE
CELERY_TASK_RESULTS_EXPIRES = 3600
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_SEND_TASK_ERROR_EMAILS = True
CELERY_TASK_ALWAYS_EAGER = False
2017-05-08 08:29:56 -06:00
CELERY_DEFAULT_QUEUE = 'db-{0}-queue'.format(ENVIRONMENT)
2018-01-06 04:25:23 -07:00
CELERY_BROKER_URL = config('CELERY_BROKER_URL', default='redis://redis:6379/0')
CELERY_RESULT_BACKEND = config('CELERY_RESULT_BACKEND', default='redis://redis:6379/0')
CELERY_BROKER_TRANSPORT_OPTIONS = {
'visibility_timeout': config('REDIS_VISIBILITY_TIMEOUT', default=604800, cast=int),
'fanout_prefix': True
}
REDIS_CONNECT_RETRY = True
2015-04-22 05:05:30 -06:00
# API
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly',
),
2017-03-02 10:55:10 -07:00
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.TokenAuthentication',
),
2015-07-17 12:19:11 -06:00
'DEFAULT_FILTER_BACKENDS': (
'django_filters.rest_framework.DjangoFilterBackend',
)
2015-04-22 05:05:30 -06:00
}
# Security
2018-01-06 04:25:23 -07:00
SECRET_KEY = config('SECRET_KEY', default='changeme')
SECURE_HSTS_SECONDS = config('SECURE_HSTS_SECONDS', default=31536000, cast=int)
2017-02-21 10:22:39 -07:00
CSP_DEFAULT_SRC = (
"'self'",
'https://*.mapbox.com',
)
CSP_SCRIPT_SRC = (
"'self'",
'https://*.google-analytics.com',
"'unsafe-eval'",
2017-02-21 10:22:39 -07:00
)
2017-03-02 10:55:10 -07:00
CSP_IMG_SRC = (
"'self'",
'https://*.gravatar.com',
'https://*.mapbox.com',
2017-03-27 05:46:43 -06:00
'https://*.google-analytics.com',
2017-11-05 06:32:38 -07:00
'data:',
'blob:',
2017-03-02 10:55:10 -07:00
)
2017-11-05 06:32:38 -07:00
CSP_CHILD_SRC = (
'blob:',
)
2017-05-08 08:29:56 -06:00
SECURE_HSTS_INCLUDE_SUBDOMAINS = True
SECURE_CONTENT_TYPE_NOSNIFF = True
SECURE_BROWSER_XSS_FILTER = True
2018-01-06 04:25:23 -07:00
ALLOWED_HOSTS = config('ALLOWED_HOSTS', default='localhost', cast=Csv())
2015-04-22 05:05:30 -06:00
# Database
2018-01-06 04:25:23 -07:00
DATABASE_URL = config('DATABASE_URL', default='sqlite:///db.sqlite3')
DATABASES = {'default': db_url(DATABASE_URL)}
# NETWORK API
2018-01-06 04:25:23 -07:00
NETWORK_API_ENDPOINT = config('NETWORK_API_ENDPOINT', default='https://network.satnogs.org/api/')
DATA_FETCH_DAYS = config('DATA_FETCH_DAYS', default=10, cast=int)
# Mapbox API
MAPBOX_GEOCODE_URL = 'https://api.tiles.mapbox.com/v4/geocode/mapbox.places/'
2018-01-06 04:25:23 -07:00
MAPBOX_TOKEN = config('MAPBOX_TOKEN', default='')
2017-05-08 08:29:56 -06:00
# Influx DB for decoded data_id
USE_INFLUX = config('USE_INFLUX', default=False, cast=bool)
INFLUX_HOST = config('INFLUX_HOST', default='localhost')
INFLUX_PORT = config('INFLUX_PORT', default='8086')
INFLUX_USER = config('INFLUX_USER', default='db')
INFLUX_PASS = config('INFLUX_PASS', default='db')
INFLUX_DB = config('INFLUX_DB', default='db')
2017-11-13 03:30:39 -07:00
if ENVIRONMENT == 'dev':
# Disable template caching
for backend in TEMPLATES:
del backend['OPTIONS']['loaders']
backend['APP_DIRS'] = True