244 lines
5.5 KiB
Python
244 lines
5.5 KiB
Python
"""
|
|
Django settings for vector project.
|
|
|
|
Generated by 'django-admin startproject' using Django 4.2.21.
|
|
|
|
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 logging
|
|
from pathlib import Path
|
|
|
|
from django.contrib import messages
|
|
from django.urls import reverse_lazy
|
|
from django.utils.translation import gettext_lazy as _
|
|
from loadcredential import Credentials
|
|
|
|
credentials = Credentials(env_prefix="VECTOR_")
|
|
logger = logging.getLogger(__name__)
|
|
|
|
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
|
|
|
|
|
# WARNING: keep the secret key used in production secret!
|
|
SECRET_KEY = credentials["SECRET_KEY"]
|
|
|
|
# WARNING: don't run with debug turned on in production!
|
|
DEBUG = credentials.get_json("DEBUG", False)
|
|
|
|
ALLOWED_HOSTS = credentials.get_json("ALLOWED_HOSTS", [])
|
|
|
|
ADMINS = credentials.get_json("ADMINS", [])
|
|
|
|
|
|
###
|
|
# List the installed applications
|
|
|
|
INSTALLED_APPS = [
|
|
# Unfold apps
|
|
"unfold",
|
|
"unfold.contrib.import_export",
|
|
# Django standard apps
|
|
"django.contrib.admin",
|
|
"django.contrib.auth",
|
|
"django.contrib.contenttypes",
|
|
"django.contrib.sessions",
|
|
"django.contrib.messages",
|
|
"django.contrib.staticfiles",
|
|
# Custom apps
|
|
"django_browser_reload",
|
|
"bulma",
|
|
"import_export",
|
|
# Authentication
|
|
"authens",
|
|
# Main app
|
|
"vector",
|
|
]
|
|
|
|
###
|
|
# List the installed middlewares
|
|
|
|
MIDDLEWARE = [
|
|
"django.middleware.security.SecurityMiddleware",
|
|
"django.contrib.sessions.middleware.SessionMiddleware",
|
|
"django.middleware.locale.LocaleMiddleware",
|
|
"django.middleware.common.CommonMiddleware",
|
|
"django.middleware.csrf.CsrfViewMiddleware",
|
|
"django.contrib.auth.middleware.AuthenticationMiddleware",
|
|
"django.contrib.messages.middleware.MessageMiddleware",
|
|
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
|
"django_browser_reload.middleware.BrowserReloadMiddleware",
|
|
]
|
|
|
|
###
|
|
# Logging configuration
|
|
|
|
LOGGING = {
|
|
"version": 1,
|
|
"disable_existing_loggers": False,
|
|
"handlers": {
|
|
"console": {
|
|
"class": "logging.StreamHandler",
|
|
},
|
|
},
|
|
"root": {
|
|
"handlers": ["console"],
|
|
"level": credentials.get("LOG_LEVEL", "WARNING"),
|
|
},
|
|
}
|
|
|
|
###
|
|
# The main url configuration
|
|
|
|
ROOT_URLCONF = "app.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 configuration
|
|
|
|
WSGI_APPLICATION = "app.wsgi.application"
|
|
|
|
###
|
|
# Database configuration
|
|
# -> https://docs.djangoproject.com/en/4.2/ref/settings/#databases
|
|
|
|
DATABASES = credentials.get_json(
|
|
"DATABASES",
|
|
{
|
|
"default": {
|
|
"ENGINE": "django.db.backends.sqlite3",
|
|
"NAME": BASE_DIR / "db.sqlite3",
|
|
}
|
|
},
|
|
)
|
|
|
|
###
|
|
# Authentication configuration
|
|
# Disable password validation, no authentication should use local passwords
|
|
|
|
AUTH_PASSWORD_VALIDATORS = []
|
|
AUTH_USER_MODEL = "vector.User"
|
|
|
|
AUTHENTICATION_BACKENDS = [
|
|
"vector.auth.backends.CASBackend",
|
|
"sesame.backends.ModelBackend",
|
|
]
|
|
|
|
SESAME_MAX_AGE = 900
|
|
SESAME_SIGNATURE_SIZE = 24
|
|
SESAME_TOKENS = ["sesame.tokens_v2"]
|
|
|
|
LOGIN_REDIRECT_URL = reverse_lazy("vector:index")
|
|
LOGIN_URL = reverse_lazy("vector:auth:login-cas")
|
|
|
|
###
|
|
# Internationalization configuration
|
|
# -> https://docs.djangoproject.com/en/4.2/topics/i18n/
|
|
|
|
LANGUAGE_CODE = "fr"
|
|
|
|
LANGUAGES = [
|
|
("en", "English"),
|
|
("fr", "Français"),
|
|
]
|
|
|
|
LOCALE_PATHS = [
|
|
(BASE_DIR / "locale"),
|
|
]
|
|
|
|
TIME_ZONE = "Europe/Paris"
|
|
|
|
USE_I18N = True
|
|
USE_TZ = True
|
|
|
|
|
|
###
|
|
# Static files (CSS, JavaScript, Images) configuration
|
|
# -> https://docs.djangoproject.com/en/4.2/howto/static-files/
|
|
|
|
STATIC_URL = "static/"
|
|
MEDIA_URL = "media/"
|
|
|
|
STATICFILES_FINDERS = [
|
|
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
|
|
]
|
|
|
|
STATIC_ROOT = credentials.get("STATIC_ROOT")
|
|
MEDIA_ROOT = credentials.get("MEDIA_ROOT")
|
|
|
|
###
|
|
# Storages configuration
|
|
|
|
ARCHIVES_INTERNAL = credentials.get("ARCHIVES_INTERNAL", "_archives")
|
|
STORAGES = {
|
|
"default": {
|
|
"BACKEND": "django.core.files.storage.FileSystemStorage",
|
|
},
|
|
"staticfiles": {
|
|
"BACKEND": "django.contrib.staticfiles.storage.ManifestStaticFilesStorage",
|
|
},
|
|
}
|
|
|
|
###
|
|
# Default primary key field type
|
|
# -> https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
|
|
|
|
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
|
|
|
|
##
|
|
# Messages configuration
|
|
|
|
MESSAGE_TAGS = {
|
|
messages.DEBUG: "is-dark",
|
|
messages.INFO: "is-link",
|
|
messages.SUCCESS: "is-success",
|
|
messages.WARNING: "is-warning",
|
|
messages.ERROR: "is-danger",
|
|
}
|
|
|
|
|
|
###
|
|
# Unfold Interface configuration
|
|
|
|
UNFOLD = {
|
|
"SITE_HEADER": _("Administration de Vector"),
|
|
}
|
|
|
|
|
|
###
|
|
# Extend settings when running in dev mode
|
|
|
|
if DEBUG:
|
|
INSTALLED_APPS += [
|
|
"debug_toolbar",
|
|
]
|
|
|
|
MIDDLEWARE += [
|
|
"debug_toolbar.middleware.DebugToolbarMiddleware",
|
|
]
|
|
|
|
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
|
|
|
|
INTERNAL_IPS = ["127.0.0.1"]
|
|
|
|
DEBUG_TOOLBAR_CONFIG = {"INSERT_BEFORE": "</footer>"}
|