shiftregister/shiftregister/settings.py

243 lines
6.7 KiB
Python

"""
Django settings for shiftregister project.
Generated by 'django-admin startproject' using Django 4.0.3.
For more information on this file, see
https://docs.djangoproject.com/en/4.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.0/ref/settings/
"""
from pathlib import Path
import environ
import sentry_sdk
from django.contrib.messages import constants as messages
from sentry_sdk.integrations.celery import CeleryIntegration
from sentry_sdk.integrations.django import DjangoIntegration
env = environ.Env()
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
environ.Env.read_env(BASE_DIR / ".env")
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = env("ENVIRONMENT") == "development"
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = env(
"SECRET_KEY",
default=(
"django-insecure-pdgzgd_!w&&cfqc%r&!v_^6pgf!sza=2wim67()!(kaf7_6-5)"
if DEBUG
else env.NOTSET
),
)
ALLOWED_HOSTS = env.list("ALLOWED_HOSTS", default=[])
# Application definition
DJANGO_APPS = [
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.humanize",
"django.contrib.messages",
"django.contrib.sessions",
"django.contrib.staticfiles",
]
THIRDPARTY_APPS = [
"dynamic_preferences",
"phonenumber_field",
]
LOCAL_APPS = [
"shiftregister.app",
"shiftregister.core",
"shiftregister.fallback",
"shiftregister.feedback",
"shiftregister.importer",
"shiftregister.messaging",
"shiftregister.metrics",
"shiftregister.pages",
"shiftregister.signage",
"shiftregister.team",
]
INSTALLED_APPS = DJANGO_APPS + THIRDPARTY_APPS + LOCAL_APPS
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",
"shiftregister.app.middleware.check_helper",
]
ROOT_URLCONF = "shiftregister.urls"
LOGIN_URL = "/admin/login/"
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",
"shiftregister.app.context_processors.proc",
"shiftregister.core.context_processors.footer_nav",
"shiftregister.core.context_processors.nav",
],
},
},
]
WSGI_APPLICATION = "shiftregister.wsgi.application"
# Database
# https://docs.djangoproject.com/en/4.0/ref/settings/#databases
DATABASES = {
"default": env.db_url(default=f"sqlite:///{BASE_DIR / 'db.sqlite3'}"),
}
# Password validation
# https://docs.djangoproject.com/en/4.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",
},
]
# Internationalization
# https://docs.djangoproject.com/en/4.0/topics/i18n/
LANGUAGE_CODE = "de-de"
TIME_ZONE = "Europe/Berlin"
USE_I18N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.0/howto/static-files/
STATIC_ROOT = "/opt/shiftregister/static"
STATIC_URL = "static/"
# Default primary key field type
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
CELERY_BROKER_URL = env(
"CELERY_BROKER_URL", default="amqp://guest:guest@localhost:5672//"
)
CELERY_RESULT_BACKEND = env("CELERY_RESULT_BACKEND", default="redis://")
CELERY_BEAT_SCHEDULE = {
"import-shifts-every-60-seconds": {
"task": "shiftregister.importer.tasks.import_shifts",
"schedule": env.float("SHIFT_IMPORT_INTERVAL", default=60.0), # seconds
},
"send-messages-every-120-seconds": {
"task": "shiftregister.app.tasks.send_messages",
"schedule": env.float("MESSAGE_SEND_INTERVAL", default=120.0), # seconds
},
"send-reminders-every-300-seconds": {
"task": "shiftregister.app.tasks.send_reminders",
"schedule": env.float("REMINDER_SEND_INTERVAL", default=300.0), # seconds
},
"deactivate-fallbacks-every-300-seconds": {
"task": "shiftregister.fallback.tasks.deactivate_fallbacks",
"schedule": env.float("FALLBACK_DEACTIVATE_INTERVAL", default=300.0), # seconds
},
"fetch-messages-every-300-seconds": {
"task": "shiftregister.messaging.tasks.fetch_messages",
"schedule": env.float("MESSAGE_FETCH_INTERVAL", default=300.0), # seconds
},
}
CELERY_BEAT_SCHEDULE_FILENAME = str(BASE_DIR / "storage" / "celerybeat-schedule")
if env("SENTRY_DSN", default=None):
sentry_sdk.init(
dsn=env("SENTRY_DSN"),
integrations=[CeleryIntegration(), DjangoIntegration()],
auto_session_tracking=False,
traces_sample_rate=0,
)
PHONENUMBER_DEFAULT_REGION = "DE"
MESSAGE_TAGS = {
messages.ERROR: "danger",
}
# Legacy sipgate settings
SIPGATE_SMS_EXTENSION = env("SIPGATE_SMS_EXTENSION", default=None)
SIPGATE_TOKEN_ID = env("SIPGATE_TOKEN_ID", default=None)
SIPGATE_TOKEN = env("SIPGATE_TOKEN", default=None)
SIPGATE_INCOMING_TOKEN_ID = env("SIPGATE_INCOMING_TOKEN_ID", default=None)
SIPGATE_INCOMING_TOKEN = env("SIPGATE_INCOMING_TOKEN", default=None)
# New messaging settings
SMS_INBOUND_BACKEND = ".".join(
(
"shiftregister",
"messaging",
"backends",
env("SMS_INBOUND_BACKEND", default="dummy"),
)
)
SMS_OUTBOUND_BACKEND = ".".join(
(
"shiftregister",
"messaging",
"backends",
env("SMS_OUTBOUND_BACKEND", default="dummy"),
)
)
SMS_SETTINGS = env.dict("SMS_SETTINGS", default={})
SMS_WEBHOOK_SECRET = env("SMS_WEBHOOK_SECRET", default=None)