193 lines
6.8 KiB
Python
193 lines
6.8 KiB
Python
from pathlib import Path
|
|
import os
|
|
from django.core.exceptions import ImproperlyConfigured
|
|
|
|
BASE_DIR = Path(__file__).resolve().parent.parent.parent
|
|
|
|
|
|
def env_bool(key: str, default: bool = False) -> bool:
|
|
value = os.getenv(key)
|
|
if value is None:
|
|
return default
|
|
return value.strip().lower() in {"1", "true", "yes", "on"}
|
|
|
|
|
|
def env_list(key: str, default: str = "") -> list[str]:
|
|
value = os.getenv(key, default)
|
|
return [item.strip() for item in value.split(",") if item.strip()]
|
|
|
|
|
|
DJANGO_ENV = os.getenv("DJANGO_ENV", "development").strip().lower()
|
|
SECRET_KEY = os.getenv("DJANGO_SECRET_KEY", "insecure-development-secret")
|
|
DEBUG = env_bool("DJANGO_DEBUG", False)
|
|
ALLOWED_HOSTS = env_list("DJANGO_ALLOWED_HOSTS", "localhost,127.0.0.1")
|
|
CSRF_TRUSTED_ORIGINS = env_list(
|
|
"DJANGO_CSRF_TRUSTED_ORIGINS", "http://localhost,http://127.0.0.1"
|
|
)
|
|
|
|
if not DEBUG and SECRET_KEY in {"", "insecure-development-secret", "change-me-in-production"}:
|
|
raise ImproperlyConfigured("DJANGO_SECRET_KEY must be set to a strong value when DEBUG=0.")
|
|
if not DEBUG and not ALLOWED_HOSTS:
|
|
raise ImproperlyConfigured("DJANGO_ALLOWED_HOSTS must not be empty when DEBUG=0.")
|
|
|
|
INSTALLED_APPS = [
|
|
"django.contrib.admin",
|
|
"django.contrib.auth",
|
|
"django.contrib.contenttypes",
|
|
"django.contrib.sessions",
|
|
"django.contrib.messages",
|
|
"django.contrib.staticfiles",
|
|
"rest_framework",
|
|
"apps.api",
|
|
"apps.core",
|
|
"apps.users",
|
|
"apps.players",
|
|
"apps.competitions",
|
|
"apps.teams",
|
|
"apps.stats",
|
|
"apps.scouting",
|
|
"apps.providers",
|
|
"apps.ingestion",
|
|
]
|
|
|
|
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",
|
|
]
|
|
|
|
ROOT_URLCONF = "config.urls"
|
|
|
|
TEMPLATES = [
|
|
{
|
|
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
|
"DIRS": [BASE_DIR / "templates"],
|
|
"APP_DIRS": True,
|
|
"OPTIONS": {
|
|
"context_processors": [
|
|
"django.template.context_processors.request",
|
|
"django.contrib.auth.context_processors.auth",
|
|
"django.contrib.messages.context_processors.messages",
|
|
],
|
|
},
|
|
},
|
|
]
|
|
|
|
WSGI_APPLICATION = "config.wsgi.application"
|
|
ASGI_APPLICATION = "config.asgi.application"
|
|
|
|
DATABASES = {
|
|
"default": {
|
|
"ENGINE": "django.db.backends.postgresql",
|
|
"NAME": os.getenv("POSTGRES_DB", "hoopscout"),
|
|
"USER": os.getenv("POSTGRES_USER", "hoopscout"),
|
|
"PASSWORD": os.getenv("POSTGRES_PASSWORD", "hoopscout"),
|
|
"HOST": os.getenv("POSTGRES_HOST", "postgres"),
|
|
"PORT": os.getenv("POSTGRES_PORT", "5432"),
|
|
}
|
|
}
|
|
|
|
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"},
|
|
]
|
|
|
|
LANGUAGE_CODE = "en-us"
|
|
TIME_ZONE = os.getenv("DJANGO_TIME_ZONE", "UTC")
|
|
USE_I18N = True
|
|
USE_TZ = True
|
|
|
|
STATIC_URL = os.getenv("DJANGO_STATIC_URL", "/static/")
|
|
STATIC_ROOT = Path(os.getenv("DJANGO_STATIC_ROOT", str(BASE_DIR / "staticfiles")))
|
|
STATICFILES_DIRS = [BASE_DIR / "static"]
|
|
|
|
MEDIA_URL = os.getenv("DJANGO_MEDIA_URL", "/media/")
|
|
MEDIA_ROOT = Path(os.getenv("DJANGO_MEDIA_ROOT", str(BASE_DIR / "media")))
|
|
|
|
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
|
|
|
|
LOGIN_URL = "users:login"
|
|
LOGIN_REDIRECT_URL = "core:dashboard"
|
|
LOGOUT_REDIRECT_URL = "core:home"
|
|
|
|
CELERY_BROKER_URL = os.getenv("CELERY_BROKER_URL", "redis://redis:6379/0")
|
|
CELERY_RESULT_BACKEND = os.getenv("CELERY_RESULT_BACKEND", "redis://redis:6379/0")
|
|
CELERY_ACCEPT_CONTENT = ["json"]
|
|
CELERY_TASK_SERIALIZER = "json"
|
|
CELERY_RESULT_SERIALIZER = "json"
|
|
CELERY_TIMEZONE = TIME_ZONE
|
|
CELERY_TASK_TIME_LIMIT = int(os.getenv("CELERY_TASK_TIME_LIMIT", "1800"))
|
|
CELERY_TASK_SOFT_TIME_LIMIT = int(os.getenv("CELERY_TASK_SOFT_TIME_LIMIT", "1500"))
|
|
|
|
PROVIDER_BACKEND = os.getenv("PROVIDER_BACKEND", "demo").strip().lower()
|
|
PROVIDER_NAMESPACE_DEMO = os.getenv("PROVIDER_NAMESPACE_DEMO", "mvp_demo")
|
|
PROVIDER_NAMESPACE_BALLDONTLIE = os.getenv("PROVIDER_NAMESPACE_BALLDONTLIE", "balldontlie")
|
|
PROVIDER_DEFAULT_NAMESPACE = os.getenv("PROVIDER_DEFAULT_NAMESPACE", "").strip()
|
|
PROVIDER_MVP_DATA_FILE = os.getenv(
|
|
"PROVIDER_MVP_DATA_FILE",
|
|
str(BASE_DIR / "apps" / "providers" / "data" / "mvp_provider.json"),
|
|
)
|
|
PROVIDER_REQUEST_RETRIES = int(os.getenv("PROVIDER_REQUEST_RETRIES", "3"))
|
|
PROVIDER_REQUEST_RETRY_SLEEP = float(os.getenv("PROVIDER_REQUEST_RETRY_SLEEP", "1"))
|
|
PROVIDER_HTTP_TIMEOUT_SECONDS = float(os.getenv("PROVIDER_HTTP_TIMEOUT_SECONDS", "10"))
|
|
PROVIDER_BALLDONTLIE_BASE_URL = os.getenv("PROVIDER_BALLDONTLIE_BASE_URL", "https://api.balldontlie.io/v1")
|
|
PROVIDER_BALLDONTLIE_API_KEY = os.getenv("PROVIDER_BALLDONTLIE_API_KEY", "")
|
|
PROVIDER_BALLDONTLIE_PLAYERS_PAGE_LIMIT = int(os.getenv("PROVIDER_BALLDONTLIE_PLAYERS_PAGE_LIMIT", "5"))
|
|
PROVIDER_BALLDONTLIE_PLAYERS_PER_PAGE = int(os.getenv("PROVIDER_BALLDONTLIE_PLAYERS_PER_PAGE", "100"))
|
|
PROVIDER_BALLDONTLIE_STATS_PAGE_LIMIT = int(os.getenv("PROVIDER_BALLDONTLIE_STATS_PAGE_LIMIT", "10"))
|
|
PROVIDER_BALLDONTLIE_STATS_PER_PAGE = int(os.getenv("PROVIDER_BALLDONTLIE_STATS_PER_PAGE", "100"))
|
|
PROVIDER_BALLDONTLIE_SEASONS = [
|
|
int(value.strip())
|
|
for value in os.getenv("PROVIDER_BALLDONTLIE_SEASONS", "2024").split(",")
|
|
if value.strip().isdigit()
|
|
]
|
|
|
|
LOG_LEVEL = os.getenv("DJANGO_LOG_LEVEL", "INFO").upper()
|
|
LOG_SQL = env_bool("DJANGO_LOG_SQL", False)
|
|
LOGGING = {
|
|
"version": 1,
|
|
"disable_existing_loggers": False,
|
|
"formatters": {
|
|
"standard": {
|
|
"format": "%(asctime)s %(levelname)s %(name)s %(message)s",
|
|
}
|
|
},
|
|
"handlers": {
|
|
"console": {
|
|
"class": "logging.StreamHandler",
|
|
"formatter": "standard",
|
|
}
|
|
},
|
|
"root": {
|
|
"handlers": ["console"],
|
|
"level": LOG_LEVEL,
|
|
},
|
|
"loggers": {
|
|
"django.db.backends": {
|
|
"handlers": ["console"],
|
|
"level": "DEBUG" if LOG_SQL else "WARNING",
|
|
"propagate": False,
|
|
},
|
|
},
|
|
}
|
|
|
|
REST_FRAMEWORK = {
|
|
"DEFAULT_PERMISSION_CLASSES": [
|
|
"apps.api.permissions.ReadOnlyOrDeny",
|
|
],
|
|
"DEFAULT_THROTTLE_CLASSES": [
|
|
"rest_framework.throttling.AnonRateThrottle",
|
|
"rest_framework.throttling.UserRateThrottle",
|
|
],
|
|
"DEFAULT_THROTTLE_RATES": {
|
|
"anon": os.getenv("API_THROTTLE_ANON", "100/hour"),
|
|
"user": os.getenv("API_THROTTLE_USER", "1000/hour"),
|
|
},
|
|
}
|