194 lines
4.9 KiB
Python
194 lines
4.9 KiB
Python
"""
|
|
Django settings for the gestioBDS project.
|
|
"""
|
|
|
|
import os
|
|
from pathlib import Path
|
|
|
|
from loadcredential import Credentials
|
|
|
|
credentials = Credentials(env_prefix="GESTIOBDS_")
|
|
|
|
# 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", [])
|
|
|
|
SERVER_EMAIL = credentials.get("SERVER_EMAIL")
|
|
EMAIL_HOST = credentials.get("EMAIL_HOST")
|
|
|
|
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
|
|
|
|
|
|
##
|
|
# Installed Apps configuration
|
|
|
|
INSTALLED_APPS = [
|
|
"shared",
|
|
# Must be before 'django.contrib.admin'.
|
|
# https://django-autocomplete-light.readthedocs.io/en/master/install.html
|
|
"dal",
|
|
"dal_select2",
|
|
"django.contrib.auth",
|
|
"django.contrib.contenttypes",
|
|
"django.contrib.sessions",
|
|
"django.contrib.sites",
|
|
"django.contrib.messages",
|
|
"django.contrib.admin",
|
|
"django.contrib.admindocs",
|
|
"gestioasso.apps.IgnoreSrcStaticFilesConfig",
|
|
"django_cas_ng",
|
|
"bootstrapform",
|
|
"widget_tweaks",
|
|
"bds",
|
|
"events",
|
|
"clubs",
|
|
"authens",
|
|
]
|
|
|
|
|
|
##
|
|
# Middleware configuration
|
|
|
|
MIDDLEWARE = [
|
|
"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",
|
|
"django.middleware.security.SecurityMiddleware",
|
|
"django.middleware.locale.LocaleMiddleware",
|
|
]
|
|
|
|
|
|
##
|
|
# URL configuration
|
|
|
|
ROOT_URLCONF = "gestioasso.urls"
|
|
|
|
|
|
##
|
|
# Templates configuration
|
|
|
|
TEMPLATES = [
|
|
{
|
|
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
|
"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",
|
|
"django.template.context_processors.i18n",
|
|
"django.template.context_processors.media",
|
|
"django.template.context_processors.static",
|
|
]
|
|
},
|
|
}
|
|
]
|
|
|
|
|
|
##
|
|
# Database configuration
|
|
|
|
DATABASES = credentials.get_json(
|
|
"DATABASES",
|
|
default={
|
|
"default": {
|
|
"ENGINE": "django.db.backends.sqlite3",
|
|
"NAME": (BASE_DIR / "db.sqlite3"),
|
|
}
|
|
},
|
|
)
|
|
|
|
CACHES = credentials.get_json(
|
|
"CACHES",
|
|
default={
|
|
"default": {
|
|
"BACKEND": "django.core.cache.backends.locmem.LocMemCache",
|
|
},
|
|
},
|
|
)
|
|
|
|
CORS_ORIGIN_WHITELIST = credentials.get("CORS_ORIGIN_WHITELIST", [])
|
|
|
|
|
|
SITE_ID = 1
|
|
|
|
|
|
###
|
|
# Staticfiles configuration
|
|
|
|
STATIC_ROOT = credentials["STATIC_ROOT"]
|
|
STATIC_URL = "/static/"
|
|
|
|
MEDIA_ROOT = credentials.get("MEDIA_ROOT", (BASE_DIR / "media"))
|
|
MEDIA_URL = "/media/"
|
|
|
|
|
|
##
|
|
# Authens and Authentication configuration
|
|
|
|
AUTHENTICATION_BACKENDS = [
|
|
"django.contrib.auth.backends.ModelBackend",
|
|
"authens.backends.ENSCASBackend",
|
|
"authens.backends.OldCASBackend",
|
|
]
|
|
|
|
AUTHENS_USE_OLDCAS = False
|
|
|
|
LOGIN_URL = "authens:login"
|
|
LOGIN_REDIRECT_URL = "bds:home"
|
|
LOGOUT_REDIRECT_URL = "bds:home"
|
|
|
|
|
|
# ---
|
|
# Internationalization
|
|
# https://docs.djangoproject.com/en/1.8/topics/i18n/
|
|
# ---
|
|
|
|
LANGUAGE_CODE = "fr-fr"
|
|
TIME_ZONE = "Europe/Paris"
|
|
USE_I18N = True
|
|
USE_L10N = True
|
|
USE_TZ = True
|
|
LANGUAGES = (("fr", "Français"), ("en", "English"))
|
|
FORMAT_MODULE_PATH = "gestioasso.locale"
|
|
|
|
##
|
|
# Development configuration
|
|
|
|
if DEBUG:
|
|
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
|
|
|
|
def show_toolbar(request):
|
|
"""
|
|
On active la debug-toolbar en mode développement local sauf :
|
|
- dans l'admin où ça ne sert pas à grand chose;
|
|
- si la variable d'environnement DJANGO_NO_DDT est à 1 → ça permet de la désactiver
|
|
sans modifier ce fichier en exécutant `export DJANGO_NO_DDT=1` dans le terminal
|
|
qui lance `./manage.py runserver`.
|
|
|
|
Autre side effect de cette fonction : on ne fait pas la vérification de INTERNAL_IPS
|
|
que ferait la debug-toolbar par défaut, ce qui la fait fonctionner aussi à
|
|
l'intérieur de Vagrant (comportement non testé depuis un moment…)
|
|
"""
|
|
|
|
env_no_ddt = bool(os.environ.get("DJANGO_NO_DDT", None))
|
|
return not (env_no_ddt or request.path.startswith("/admin/"))
|
|
|
|
##
|
|
# Django Debug Toolbar configuration
|
|
|
|
DEBUG_TOOLBAR_CONFIG = {"SHOW_TOOLBAR_CALLBACK": show_toolbar}
|
|
INSTALLED_APPS += ["debug_toolbar"]
|
|
MIDDLEWARE = ["debug_toolbar.middleware.DebugToolbarMiddleware"] + MIDDLEWARE
|