233 lines
6.4 KiB
Python
233 lines
6.4 KiB
Python
"""
|
|
Django settings for core project.
|
|
|
|
Generated by 'django-admin startproject' using Django 4.2.7.
|
|
|
|
For more information on this file, see
|
|
https://docs.djangoproject.com/en/4.2/topics/settings/
|
|
|
|
For the full list of settings and their values, see
|
|
https://docs.djangoproject.com/en/4.2/ref/settings/
|
|
"""
|
|
import os
|
|
import sys
|
|
|
|
import dotenv
|
|
from pathlib import Path
|
|
|
|
|
|
def truthy_str(s):
|
|
return s.lower() in ['true', '1', 't', 'y', 'yes', 'yeah', 'yup', 'certainly', 'sure', 'positive', 'uh-huh', '👍']
|
|
|
|
|
|
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
|
|
|
dotenv.load_dotenv(BASE_DIR / '.env')
|
|
|
|
# Quick-start development settings - unsuitable for production
|
|
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/
|
|
|
|
# SECURITY WARNING: keep the secret key used in production secret!
|
|
SECRET_KEY = os.getenv('DJANGO_SECRET_KEY', 'django-insecure-tm*$w_14iqbiy-!7(8#ba7j+_@(7@rf2&a^!=shs&$03b%2*rv')
|
|
|
|
# SECURITY WARNING: don't run with debug turned on in production!
|
|
DEBUG = truthy_str(os.getenv('DEBUG_MODE_ACTIVE', 'False'))
|
|
|
|
PRIMARY_HOST = os.getenv('HTTP_HOST', 'localhost')
|
|
|
|
ALLOWED_HOSTS = [PRIMARY_HOST]
|
|
|
|
MAIL_DOMAIN = os.getenv('MAIL_DOMAIN', 'localhost')
|
|
|
|
CSRF_TRUSTED_ORIGINS = ["https://" + host for host in ALLOWED_HOSTS]
|
|
|
|
LEGACY_USER_NAME = os.getenv('LEGACY_API_USER', 'legacy_user')
|
|
LEGACY_USER_PASSWORD = os.getenv('LEGACY_API_PASSWORD', 'legacy_password')
|
|
|
|
SYSTEM3_VERSION = "0.0.0-dev.0"
|
|
|
|
ACTIVE_SPAM_TRAINING = truthy_str(os.getenv('ACTIVE_SPAM_TRAINING', 'False'))
|
|
|
|
TELEGRAM_BOT_TOKEN = os.getenv('TELEGRAM_BOT_TOKEN', '1234567890:ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghi')
|
|
|
|
TELEGRAM_GROUP_CHAT_ID = os.getenv('TELEGRAM_GROUP_CHAT_ID', '-1234567890')
|
|
|
|
# Application definition
|
|
|
|
INSTALLED_APPS = [
|
|
'django.contrib.admin',
|
|
'django.contrib.auth',
|
|
'django.contrib.contenttypes',
|
|
'django.contrib.sessions',
|
|
'django.contrib.messages',
|
|
'django.contrib.staticfiles',
|
|
'django_extensions',
|
|
'django_prometheus',
|
|
'rest_framework',
|
|
'knox',
|
|
'drf_yasg',
|
|
'channels',
|
|
'authentication',
|
|
'notifications',
|
|
'files',
|
|
'tickets',
|
|
'inventory',
|
|
'mail',
|
|
'notify_sessions',
|
|
]
|
|
|
|
REST_FRAMEWORK = {
|
|
'TEST_REQUEST_DEFAULT_FORMAT': 'json',
|
|
'DEFAULT_AUTHENTICATION_CLASSES': ('knox.auth.TokenAuthentication',),
|
|
'DEFAULT_PERMISSION_CLASSES': (
|
|
'rest_framework.permissions.IsAuthenticated', 'rest_framework.permissions.DjangoModelPermissions'),
|
|
}
|
|
|
|
AUTH_USER_MODEL = 'authentication.ExtendedUser'
|
|
|
|
SWAGGER_SETTINGS = {
|
|
'SECURITY_DEFINITIONS': {
|
|
'api_key': {
|
|
'type': 'apiKey',
|
|
'in': 'header',
|
|
'name': 'Authorization'
|
|
}
|
|
},
|
|
'USE_SESSION_AUTH': False,
|
|
'JSON_EDITOR': True,
|
|
'DEFAULT_INFO': 'core.urls.openapi_info',
|
|
}
|
|
|
|
MIDDLEWARE = [
|
|
'django_prometheus.middleware.PrometheusBeforeMiddleware',
|
|
'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.clickjacking.XFrameOptionsMiddleware',
|
|
'django_prometheus.middleware.PrometheusAfterMiddleware',
|
|
]
|
|
|
|
ROOT_URLCONF = 'core.urls'
|
|
|
|
TEMPLATES = [
|
|
{
|
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
|
'DIRS': [BASE_DIR / 'templates'],
|
|
'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',
|
|
],
|
|
},
|
|
},
|
|
]
|
|
|
|
WSGI_APPLICATION = 'core.wsgi.application'
|
|
|
|
# Database
|
|
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases
|
|
|
|
if 'test' in sys.argv:
|
|
DATABASES = {
|
|
'default': {
|
|
'ENGINE': 'django.db.backends.sqlite3',
|
|
'NAME': ':memory:',
|
|
}
|
|
}
|
|
else:
|
|
DATABASES = {
|
|
'default': {
|
|
'ENGINE': 'django.db.backends.mysql',
|
|
'HOST': os.getenv('DB_HOST', 'localhost'),
|
|
'PORT': os.getenv('DB_PORT', '3306'),
|
|
'NAME': os.getenv('DB_NAME', 'system3'),
|
|
'USER': os.getenv('DB_USER', 'system3'),
|
|
'PASSWORD': os.getenv('DB_PASSWORD', 'system3'),
|
|
'OPTIONS': {
|
|
'charset': 'utf8mb4',
|
|
'init_command': "SET sql_mode='STRICT_TRANS_TABLES'"
|
|
}
|
|
}
|
|
}
|
|
|
|
# Password validation
|
|
# https://docs.djangoproject.com/en/4.2/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',
|
|
},
|
|
]
|
|
|
|
# Internationalization
|
|
# https://docs.djangoproject.com/en/4.2/topics/i18n/
|
|
|
|
LANGUAGE_CODE = 'en-us'
|
|
|
|
TIME_ZONE = 'UTC'
|
|
|
|
USE_I18N = True
|
|
|
|
USE_TZ = True
|
|
|
|
# Static files (CSS, JavaScript, Images)
|
|
# https://docs.djangoproject.com/en/4.2/howto/static-files/
|
|
|
|
STATIC_ROOT = os.getenv('STATIC_ROOT', 'staticfiles')
|
|
STATIC_URL = '/static/'
|
|
|
|
MEDIA_ROOT = os.getenv('MEDIA_ROOT', 'userfiles')
|
|
MEDIA_URL = '/media/'
|
|
|
|
STORAGES = {
|
|
'default': {
|
|
'BACKEND': 'django.core.files.storage.FileSystemStorage',
|
|
'OPTIONS': {
|
|
'base_url': MEDIA_URL,
|
|
'location': BASE_DIR / MEDIA_ROOT
|
|
},
|
|
},
|
|
'staticfiles': {
|
|
'BACKEND': 'django.core.files.storage.FileSystemStorage',
|
|
'OPTIONS': {
|
|
'base_url': STATIC_URL,
|
|
'location': BASE_DIR / STATIC_ROOT
|
|
},
|
|
},
|
|
}
|
|
DATA_UPLOAD_MAX_MEMORY_SIZE = 1024 * 1024 * 128 # 128 MB
|
|
|
|
# Default primary key field type
|
|
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
|
|
|
|
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
|
|
|
CHANNEL_LAYERS = {
|
|
'default': {
|
|
'BACKEND': 'channels_redis.core.RedisChannelLayer',
|
|
'CONFIG': {
|
|
'hosts': [(os.getenv('REDIS_HOST', 'localhost'), 6379)],
|
|
},
|
|
}
|
|
|
|
}
|
|
|
|
PROMETHEUS_METRIC_NAMESPACE = 'c3lf'
|
|
|
|
TEST_RUNNER = 'core.test_runner.FastTestRunner'
|