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
|
2017-02-08 19:14:24 +00:00
|
|
|
|
|
|
|
import datetime
|
2017-05-21 18:18:56 +00:00
|
|
|
|
|
|
|
import tzlocal
|
2016-09-22 22:18:35 +00:00
|
|
|
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/
|
|
|
|
|
2017-07-10 17:28:06 +00:00
|
|
|
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!@#$%^&*(-_=+)'
|
2017-07-28 14:57:50 +00:00
|
|
|
secret = get_random_string(50, chars)
|
2017-07-10 17:28:06 +00:00
|
|
|
with open(os.path.join(current_dir, 'secret_key.py'), 'w') as f:
|
2017-07-28 14:57:50 +00:00
|
|
|
f.write("SECRET_KEY='{}'".format(secret))
|
|
|
|
SECRET_KEY=secret
|
2017-07-10 17:28:06 +00:00
|
|
|
|
|
|
|
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']
|
2017-07-10 18:21:59 +00:00
|
|
|
|
2017-05-19 20:15:26 +00:00
|
|
|
TESTING = sys.argv[1:2] == ['test']
|
2018-02-16 20:07:53 +00:00
|
|
|
WORKER_RUNNING = sys.argv[2:3] == ["worker"]
|
2017-07-10 18:21:59 +00:00
|
|
|
|
|
|
|
# SECURITY WARNING: don't run with debug turned on a public facing server!
|
2017-11-18 15:55:22 +00:00
|
|
|
DEBUG = os.environ.get('WO_DEBUG', 'YES') == 'YES' or TESTING
|
|
|
|
SESSION_COOKIE_SECURE = CSRF_COOKIE_SECURE = os.environ.get('WO_SSL', 'NO') == 'YES'
|
2016-11-10 17:26:04 +00:00
|
|
|
INTERNAL_IPS = ['127.0.0.1']
|
2016-08-10 20:23:17 +00:00
|
|
|
|
2017-02-11 15:25:00 +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',
|
2017-05-21 18:18:56 +00:00
|
|
|
'django_filters',
|
2016-10-04 20:36:08 +00:00
|
|
|
'guardian',
|
2016-09-30 19:07:09 +00:00
|
|
|
'rest_framework',
|
2016-10-13 16:21:12 +00:00
|
|
|
'rest_framework_nested',
|
2016-10-08 16:35:22 +00:00
|
|
|
'webpack_loader',
|
2017-03-21 20:45:14 +00:00
|
|
|
'corsheaders',
|
2017-11-06 18:45:14 +00:00
|
|
|
'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'),
|
2018-03-01 21:29:23 +00:00
|
|
|
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',
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
2016-10-04 20:36:08 +00:00
|
|
|
# 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'
|
2017-05-21 18:18:56 +00:00
|
|
|
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/'
|
2017-05-19 20:15:26 +00:00
|
|
|
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
|
2017-07-10 19:13:23 +00:00
|
|
|
DATA_UPLOAD_MAX_NUMBER_FIELDS = None
|
2016-08-10 20:23:17 +00:00
|
|
|
|
2017-07-10 21:41:37 +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'),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-10-07 23:07:47 +00:00
|
|
|
# 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',
|
2016-10-11 22:08:01 +00:00
|
|
|
# 'filters': ['require_debug_true'],
|
2016-10-07 23:07:47 +00:00
|
|
|
'class': 'logging.StreamHandler',
|
|
|
|
'formatter': 'simple'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'loggers': {
|
|
|
|
'django': {
|
|
|
|
'handlers': ['console'],
|
|
|
|
'propagate': True,
|
2016-12-10 18:28:34 +00:00
|
|
|
'level': 'WARNING',
|
2016-10-07 23:07:47 +00:00
|
|
|
},
|
|
|
|
'app.logger': {
|
|
|
|
'handlers': ['console'],
|
|
|
|
'level': 'INFO',
|
2016-10-24 18:14:35 +00:00
|
|
|
},
|
|
|
|
'apscheduler.executors.default': {
|
|
|
|
'handlers': ['console'],
|
2016-12-10 18:28:34 +00:00
|
|
|
'level': 'WARNING',
|
2016-10-07 23:07:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-10 20:23:17 +00:00
|
|
|
# Auth
|
2016-08-13 17:57:24 +00:00
|
|
|
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
|
2016-10-13 20:28:32 +00:00
|
|
|
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')
|
2018-03-29 21:28:15 +00:00
|
|
|
MEDIA_TMP = os.path.join(MEDIA_ROOT, 'tmp')
|
2016-09-11 21:18:39 +00:00
|
|
|
|
2016-09-22 22:18:35 +00:00
|
|
|
# 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': [
|
2016-10-07 23:07:47 +00:00
|
|
|
'app.permissions.GuardianObjectPermissions',
|
|
|
|
],
|
|
|
|
'DEFAULT_FILTER_BACKENDS': [
|
2017-07-28 14:57:50 +00:00
|
|
|
'rest_framework.filters.DjangoObjectPermissionsFilter',
|
2018-03-11 14:51:55 +00:00
|
|
|
'django_filters.rest_framework.DjangoFilterBackend',
|
2016-11-04 18:19:18 +00:00
|
|
|
'rest_framework.filters.OrderingFilter',
|
2016-09-30 19:07:09 +00:00
|
|
|
],
|
2017-02-08 17:30:11 +00:00
|
|
|
'DEFAULT_AUTHENTICATION_CLASSES': (
|
|
|
|
'rest_framework.authentication.SessionAuthentication',
|
|
|
|
'rest_framework.authentication.BasicAuthentication',
|
|
|
|
'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
|
2017-04-10 21:19:04 +00:00
|
|
|
'app.api.authentication.JSONWebTokenAuthenticationQS',
|
2017-02-08 17:30:11 +00:00
|
|
|
),
|
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
|
|
|
}
|
|
|
|
|
2017-02-08 19:14:24 +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
|
|
|
|
2018-02-15 21:23:29 +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']
|
2018-02-19 20:50:26 +00:00
|
|
|
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
|
2018-02-15 21:23:29 +00:00
|
|
|
|
2016-09-11 21:18:39 +00:00
|
|
|
try:
|
|
|
|
from .local_settings import *
|
|
|
|
except ImportError:
|
2017-02-11 15:25:00 +00:00
|
|
|
pass
|