website/hub/settings.py

198 lines
5 KiB
Python
Raw Normal View History

2025-01-27 14:58:23 +01:00
from pathlib import Path
2025-01-27 15:07:38 +01:00
from environs import Env
env = Env()
env.read_env()
2025-01-27 14:58:23 +01:00
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
2025-01-27 17:42:40 +01:00
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"verbose": {
"format": "{levelname} {asctime} {module} {process:d} {thread:d} {message}",
"style": "{",
},
},
"handlers": {
"console": {
"class": "logging.StreamHandler",
"formatter": "verbose",
}
},
"loggers": {
"odoo_api": {
"handlers": ["console"],
"level": "DEBUG",
"propagate": True,
},
},
}
2025-01-27 14:58:23 +01:00
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
2025-01-30 15:12:50 +01:00
SECRET_KEY = env.str("SECRET_KEY")
2025-01-27 14:58:23 +01:00
# SECURITY WARNING: don't run with debug turned on in production!
2025-01-27 15:07:38 +01:00
DEBUG = env.bool("DEBUG", default=False)
2025-01-27 14:58:23 +01:00
2025-01-27 15:07:38 +01:00
ALLOWED_HOSTS = env.list("ALLOWED_HOSTS", default=[])
CSRF_TRUSTED_ORIGINS = [f"https://{h}" for h in ALLOWED_HOSTS]
2025-01-27 14:58:23 +01:00
# Application definition
INSTALLED_APPS = [
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
2025-01-27 15:35:09 +01:00
# 3rd party
"django_prose_editor",
2025-01-27 17:42:40 +01:00
"rest_framework",
2025-01-28 13:55:43 +01:00
"schema_viewer",
2025-01-27 15:35:09 +01:00
# local
2025-01-30 11:23:25 +01:00
"hub.services",
"hub.servicebroker",
2025-01-27 14:58:23 +01:00
]
2025-01-27 15:07:38 +01:00
if DEBUG:
INSTALLED_APPS += ["django_browser_reload"]
2025-01-27 14:58:23 +01:00
MIDDLEWARE = [
"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",
]
2025-01-27 15:07:38 +01:00
if DEBUG:
MIDDLEWARE += [
"django_browser_reload.middleware.BrowserReloadMiddleware",
]
2025-01-27 14:58:23 +01:00
ROOT_URLCONF = "hub.urls"
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
"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 = "hub.wsgi.application"
# Database
# https://docs.djangoproject.com/en/5.1/ref/settings/#databases
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": env.str("DB_FILE", default=str(BASE_DIR / "db.sqlite3")),
"OPTIONS": {
"transaction_mode": "IMMEDIATE",
"timeout": 5,
"init_command": """
PRAGMA journal_mode=WAL;
PRAGMA synchronous=NORMAL;
PRAGMA mmap_size = 134217728;
PRAGMA journal_size_limit = 27103364;
PRAGMA cache_size=2000;
""",
},
2025-01-27 14:58:23 +01:00
}
}
# Password validation
# https://docs.djangoproject.com/en/5.1/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/5.1/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/5.1/howto/static-files/
STATIC_URL = "static/"
2025-01-30 15:12:50 +01:00
STATIC_ROOT = env.path("STATIC_ROOT", default=BASE_DIR / "static")
2025-01-27 14:58:23 +01:00
# Default primary key field type
# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
2025-01-27 15:07:38 +01:00
MEDIA_URL = "/media/"
MEDIA_ROOT = env.path("MEDIA_ROOT", default=BASE_DIR / "media")
2025-01-27 16:51:23 +01:00
ODOO_CONFIG = {
2025-01-30 11:23:25 +01:00
"url": env.str("ODOO_URL", default="http://localhost:8069"),
"db": env.str("ODOO_DB", default="odoo"),
"username": env.str("ODOO_USERNAME", default="odoo"),
"password": env.str("ODOO_PASSWORD", default="odoo"),
2025-01-27 16:51:23 +01:00
}
2025-01-30 11:23:25 +01:00
BROKER_USERNAME = env.str("BROKER_USERNAME", default="broker")
BROKER_PASSWORD = env.str("BROKER_PASSWORD", default="secret")
2025-01-27 17:42:40 +01:00
BASE_URL = "https://your-domain.com"
REST_FRAMEWORK = {
"DEFAULT_AUTHENTICATION_CLASSES": [
2025-01-30 11:23:25 +01:00
"hub.servicebroker.authentication.ServiceBrokerAuthentication",
2025-01-27 17:42:40 +01:00
],
"UNAUTHENTICATED_USER": None,
2025-01-27 16:51:23 +01:00
}
2025-01-28 13:55:43 +01:00
SCHEMA_VIEWER = {
"apps": [
"services",
],
"exclude": {
"auth": ["User"],
},
}