201 lines
5.1 KiB
Python
201 lines
5.1 KiB
Python
"""
|
|
Django settings for rsvpproject project.
|
|
|
|
Generated by 'django-admin startproject' using Django 6.0.
|
|
|
|
For more information on this file, see
|
|
https://docs.djangoproject.com/en/6.0/topics/settings/
|
|
|
|
For the full list of settings and their values, see
|
|
https://docs.djangoproject.com/en/6.0/ref/settings/
|
|
"""
|
|
|
|
import os
|
|
from pathlib import Path
|
|
|
|
from django.contrib.messages import constants as message_constants
|
|
|
|
bool_map = {"true": True, "false": False}
|
|
|
|
|
|
def extract_bool(env_key, default: bool):
|
|
|
|
retval = default
|
|
env_val = os.getenv(env_key)
|
|
|
|
if env_val:
|
|
# Try as int
|
|
try:
|
|
bool_as_num = int(env_val)
|
|
retval = bool(bool_as_num)
|
|
# Try as string
|
|
except ValueError:
|
|
# Convert string to boolean using the dictionary
|
|
retval = bool_map.get(env_val.lower(), default)
|
|
|
|
return retval
|
|
|
|
|
|
def extract_comma_list(env_key, default=None):
|
|
if os.getenv(env_key):
|
|
return [
|
|
item.strip() for item in os.getenv(env_key).split(",")
|
|
] # pyright: ignore[reportOptionalMemberAccess]
|
|
|
|
if default:
|
|
return [default]
|
|
|
|
return []
|
|
|
|
|
|
# Quick-start development settings - unsuitable for production
|
|
# See https://docs.djangoproject.com/en/6.0/howto/deployment/checklist/
|
|
|
|
# SECURITY WARNING: keep the secret key used in production secret!
|
|
SECRET_KEY = os.getenv("SECRET_KEY", "INSECURE_STANDARD_KEY_SET_IN_ENV")
|
|
|
|
# SECURITY WARNING: don't run with debug turned on in production!
|
|
DEBUG = extract_bool("DEBUG", False)
|
|
DOCKER = extract_bool("DOCKER", False)
|
|
|
|
ALLOWED_HOSTS = extract_comma_list("ALLOWED_HOSTS", "127.0.0.1")
|
|
CSRF_TRUSTED_ORIGINS = extract_comma_list("CSRF_TRUSTED_ORIGINS")
|
|
|
|
|
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
|
DOCKER_DIR = BASE_DIR
|
|
|
|
if DOCKER:
|
|
# We are running in docker
|
|
DOCKER_DIR = Path("/data")
|
|
|
|
# Application definition
|
|
|
|
INSTALLED_APPS = [
|
|
"daphne",
|
|
"django.contrib.admin",
|
|
"django.contrib.auth",
|
|
"django.contrib.contenttypes",
|
|
"django.contrib.sessions",
|
|
"django.contrib.messages",
|
|
"django.contrib.staticfiles",
|
|
"events",
|
|
]
|
|
|
|
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 = "rsvpproject.urls"
|
|
|
|
TEMPLATES = [
|
|
{
|
|
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
|
"DIRS": [],
|
|
"APP_DIRS": True,
|
|
"OPTIONS": {
|
|
"context_processors": [
|
|
"django.template.context_processors.request",
|
|
"django.contrib.auth.context_processors.auth",
|
|
"django.contrib.messages.context_processors.messages",
|
|
"django.template.context_processors.csrf",
|
|
],
|
|
},
|
|
},
|
|
]
|
|
|
|
LOGGING = {
|
|
"version": 1,
|
|
"disable_existing_loggers": False,
|
|
"formatters": {
|
|
"standard": {"format": "%(asctime)s [%(levelname)s] %(name)s: %(message)s"},
|
|
"simple": {"format": "%(levelname)s %(message)s"},
|
|
},
|
|
"handlers": {
|
|
"console": {
|
|
"class": "logging.StreamHandler",
|
|
"formatter": "standard",
|
|
},
|
|
# 'file': {
|
|
# 'level': 'DEBUG' if DEBUG else 'INFO',
|
|
# 'class': 'logging.FileHandler',
|
|
# 'filename': 'error.log',
|
|
# 'formatter': 'simple',
|
|
# },
|
|
},
|
|
"loggers": {
|
|
"events": {
|
|
"handlers": ["console"],
|
|
"level": "DEBUG" if DEBUG else "INFO",
|
|
"propagate": True,
|
|
},
|
|
},
|
|
}
|
|
|
|
ASGI_APPLICATION = "rsvpproject.asgi.application"
|
|
|
|
|
|
# Database
|
|
# https://docs.djangoproject.com/en/6.0/ref/settings/#databases
|
|
|
|
DATABASES = {
|
|
"default": {
|
|
"ENGINE": "django.db.backends.sqlite3",
|
|
"NAME": DOCKER_DIR / "db.sqlite3",
|
|
}
|
|
}
|
|
|
|
CHANNEL_LAYERS = {"default": {"BACKEND": "channels.layers.InMemoryChannelLayer"}}
|
|
|
|
# Password validation
|
|
# https://docs.djangoproject.com/en/6.0/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",
|
|
},
|
|
]
|
|
|
|
MESSAGE_TAGS = {
|
|
message_constants.INFO: "bg-blue",
|
|
message_constants.SUCCESS: "bg-green",
|
|
message_constants.WARNING: "bg-orange",
|
|
message_constants.ERROR: "bg-red",
|
|
}
|
|
|
|
# Internationalization
|
|
# https://docs.djangoproject.com/en/6.0/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/6.0/howto/static-files/
|
|
|
|
STATIC_URL = "static/"
|
|
STATIC_ROOT = BASE_DIR / "static"
|
|
|
|
MEDIA_URL = "media/"
|
|
MEDIA_ROOT = DOCKER_DIR / "media"
|