OpenDroneMap-WebODM/webodm/settings.py

339 wiersze
8.9 KiB
Python
Czysty Zwykły widok Historia

2016-08-10 20:23:17 +00:00
"""
Django settings for webodm project.
Generated by 'django-admin startproject' using Django 1.10.
For more information on this file, see
https://docs.djangoproject.com/en/1.10/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.10/ref/settings/
"""
2018-02-09 18:46:45 +00:00
import os, sys, json
import datetime
import tzlocal
from django.contrib.messages import constants as messages
2016-08-10 20:23:17 +00:00
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/
try:
from .secret_key import SECRET_KEY
except ImportError:
# This will be executed the first time Django runs
# It generates a secret_key.py file that contains the SECRET_KEY
from django.utils.crypto import get_random_string
current_dir = os.path.abspath(os.path.dirname(__file__))
chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)'
secret = get_random_string(50, chars)
with open(os.path.join(current_dir, 'secret_key.py'), 'w') as f:
f.write("SECRET_KEY='{}'".format(secret))
SECRET_KEY=secret
print("Generated secret key")
2018-02-09 18:46:45 +00:00
with open(os.path.join(BASE_DIR, 'package.json')) as package_file:
data = json.load(package_file)
VERSION = data['version']
TESTING = sys.argv[1:2] == ['test']
WORKER_RUNNING = sys.argv[2:3] == ["worker"]
# SECURITY WARNING: don't run with debug turned on a public facing server!
DEBUG = os.environ.get('WO_DEBUG', 'YES') == 'YES' or TESTING
SESSION_COOKIE_SECURE = CSRF_COOKIE_SECURE = os.environ.get('WO_SSL', 'NO') == 'YES'
INTERNAL_IPS = ['127.0.0.1']
2016-08-10 20:23:17 +00:00
ALLOWED_HOSTS = ['*']
2016-08-10 20:23:17 +00:00
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
2016-11-07 17:10:01 +00:00
'django.contrib.gis',
'django_filters',
'guardian',
2016-09-30 19:07:09 +00:00
'rest_framework',
'rest_framework_nested',
2016-10-08 16:35:22 +00:00
'webpack_loader',
2017-03-21 20:45:14 +00:00
'corsheaders',
'colorfield',
'imagekit',
2017-11-06 22:43:47 +00:00
'codemirror2',
2017-11-07 21:48:27 +00:00
'compressor',
2016-08-10 20:23:17 +00:00
'app',
2016-09-30 19:07:09 +00:00
'nodeodm',
2016-08-10 20:23:17 +00:00
]
MIDDLEWARE = [
2017-03-21 20:45:14 +00:00
'corsheaders.middleware.CorsMiddleware',
2016-08-10 20:23:17 +00:00
'django.middleware.security.SecurityMiddleware',
'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.locale.LocaleMiddleware',
]
ROOT_URLCONF = 'webodm.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join(BASE_DIR, 'app', 'templates'),
os.path.join(BASE_DIR, 'app', 'templates', 'app'),
BASE_DIR
2016-08-10 20:23:17 +00:00
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
2017-11-07 18:40:12 +00:00
'app.contexts.settings.load',
2016-08-10 20:23:17 +00:00
],
},
},
]
WSGI_APPLICATION = 'webodm.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.10/ref/settings/#databases
DATABASES = {
'default': {
2016-11-07 17:10:01 +00:00
'ENGINE': 'django.contrib.gis.db.backends.postgis',
2016-08-10 20:23:17 +00:00
'NAME': 'webodm_dev',
'USER': 'postgres',
'PASSWORD': 'postgres',
2016-09-11 23:52:31 +00:00
'HOST': 'db',
2016-08-10 20:23:17 +00:00
'PORT': '5432',
}
}
# Password validation
# https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Hook guardian
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend', # this is default
'guardian.backends.ObjectPermissionBackend',
)
2016-08-10 20:23:17 +00:00
# Internationalization
# https://docs.djangoproject.com/en/1.10/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = tzlocal.get_localzone().zone
2016-08-10 20:23:17 +00:00
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.10/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'build', 'static')
2016-08-10 20:23:17 +00:00
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'app', 'static'),
]
2017-11-07 21:48:27 +00:00
STATICFILES_FINDERS = [
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'compressor.finders.CompressorFinder',
]
2016-08-10 20:23:17 +00:00
2017-07-10 16:38:32 +00:00
# File Uploads
FILE_UPLOAD_MAX_MEMORY_SIZE = 4718592 # 4.5 MB
DATA_UPLOAD_MAX_NUMBER_FIELDS = None
2016-08-10 20:23:17 +00:00
FILE_UPLOAD_HANDLERS = [
'django.core.files.uploadhandler.MemoryFileUploadHandler',
'app.uploadhandler.TemporaryFileUploadHandler', # Ours doesn't keep file descriptors open by default
]
2016-10-08 16:35:22 +00:00
# Webpack
WEBPACK_LOADER = {
'DEFAULT': {
'BUNDLE_DIR_NAME': 'app/bundles/',
'STATS_FILE': os.path.join(BASE_DIR, 'webpack-stats.json'),
}
}
# Logging
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
},
'simple': {
'format': '%(levelname)s %(message)s'
},
},
'filters': {
'require_debug_true': {
'()': 'django.utils.log.RequireDebugTrue',
},
},
'handlers': {
'console': {
'level': 'INFO',
# 'filters': ['require_debug_true'],
'class': 'logging.StreamHandler',
'formatter': 'simple'
}
},
'loggers': {
'django': {
'handlers': ['console'],
'propagate': True,
'level': 'WARNING',
},
'app.logger': {
'handlers': ['console'],
'level': 'INFO',
},
'apscheduler.executors.default': {
'handlers': ['console'],
'level': 'WARNING',
}
}
}
2016-08-10 20:23:17 +00:00
# Auth
LOGIN_REDIRECT_URL = '/dashboard/'
2016-09-10 15:24:16 +00:00
LOGIN_URL = '/login/'
2017-03-21 20:45:14 +00:00
# CORS (very relaxed settings, users might want to change this in production)
CORS_ORIGIN_ALLOW_ALL = True
2018-03-31 17:08:56 +00:00
CORS_ALLOW_CREDENTIALS = True
2017-03-21 20:45:14 +00:00
2016-09-10 15:24:16 +00:00
# File uploads
MEDIA_ROOT = os.path.join(BASE_DIR, 'app', 'media')
2018-05-13 17:30:44 +00:00
if TESTING:
MEDIA_ROOT = os.path.join(BASE_DIR, 'app', 'media_test')
MEDIA_TMP = os.path.join(MEDIA_ROOT, 'tmp')
# Store flash messages in cookies
MESSAGE_STORAGE = 'django.contrib.messages.storage.cookie.CookieStorage'
MESSAGE_TAGS = {
messages.ERROR: 'danger' # Bootstrap 3 compatibility
}
2016-09-30 19:07:09 +00:00
# REST setup
# Use Django's standard django.contrib.auth permissions (no anonymous usage)
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': [
'app.permissions.GuardianObjectPermissions',
],
'DEFAULT_FILTER_BACKENDS': [
'rest_framework.filters.DjangoObjectPermissionsFilter',
2018-03-11 14:51:55 +00:00
'django_filters.rest_framework.DjangoFilterBackend',
'rest_framework.filters.OrderingFilter',
2016-09-30 19:07:09 +00:00
],
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.BasicAuthentication',
'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
'app.api.authentication.JSONWebTokenAuthenticationQS',
),
2016-09-30 19:07:09 +00:00
'PAGE_SIZE': 10,
2018-03-11 14:51:55 +00:00
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
2016-09-30 19:07:09 +00:00
}
JWT_AUTH = {
'JWT_EXPIRATION_DELTA': datetime.timedelta(hours=6),
}
2017-11-07 21:48:27 +00:00
# Compressor
COMPRESS_PRECOMPILERS = (
('text/x-scss', 'django_libsass.SassCompiler'),
)
# Sass
def theme(color):
2017-11-08 20:13:35 +00:00
from app.contexts.settings import theme as f
return f(color)
2017-11-07 21:48:27 +00:00
2017-11-08 20:13:35 +00:00
def complementary(color):
from app.contexts.settings import complementary as f
return f(color)
def scaleby(color, n):
from app.contexts.settings import scaleby as f
return f(color, n)
2017-11-09 17:37:04 +00:00
def scalebyiv(color, n):
from app.contexts.settings import scaleby as f
return f(color, n, True)
2017-11-08 20:13:35 +00:00
LIBSASS_CUSTOM_FUNCTIONS = {
'theme': theme,
'complementary': complementary,
2017-11-09 17:37:04 +00:00
'scaleby': scaleby,
'scalebyiv': scalebyiv
2017-11-08 20:13:35 +00:00
}
2017-11-07 21:48:27 +00:00
# Celery
CELERY_BROKER_URL = os.environ.get('WO_BROKER', 'redis://localhost')
CELERY_RESULT_BACKEND = os.environ.get('WO_BROKER', 'redis://localhost')
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_ACCEPT_CONTENT = ['json']
CELERY_INCLUDE=['worker.tasks']
CELERY_WORKER_REDIRECT_STDOUTS = False
CELERY_WORKER_HIJACK_ROOT_LOGGER = False
2018-04-19 18:55:09 +00:00
2018-02-17 17:35:03 +00:00
if TESTING:
CELERY_TASK_ALWAYS_EAGER = True
try:
from .local_settings import *
except ImportError:
pass