kadenios/app/settings/common.py

152 lines
4.2 KiB
Python
Raw Normal View History

2020-12-19 18:01:35 +01:00
"""
Paramètres communs entre dev et prod
2020-12-19 18:01:35 +01:00
"""
import os
import sys
2020-12-19 18:01:35 +01:00
2021-01-26 14:26:35 +01:00
from django.urls import reverse_lazy
2021-04-14 03:22:22 +02:00
from django.utils.translation import gettext_lazy as _
2021-01-26 14:26:35 +01:00
# #############################################################################
# Secrets
# #############################################################################
try:
from . import secret
except ImportError:
raise ImportError(
"The secret.py file is missing.\n"
"For a development environment, simply copy secret_example.py"
)
2020-12-19 18:01:35 +01:00
def import_secret(name):
"""
Shorthand for importing a value from the secret module and raising an
informative exception if a secret is missing.
"""
try:
return getattr(secret, name)
except AttributeError:
raise RuntimeError("Secret missing: {}".format(name))
2020-12-19 18:01:35 +01:00
SECRET_KEY = import_secret("SECRET_KEY")
ADMINS = import_secret("ADMINS")
SERVER_EMAIL = import_secret("SERVER_EMAIL")
EMAIL_HOST = import_secret("EMAIL_HOST")
2020-12-19 18:01:35 +01:00
# #############################################################################
# Paramètres par défaut pour Django
# #############################################################################
DEBUG = False
TESTING = len(sys.argv) > 1 and sys.argv[1] == "test"
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
2020-12-19 18:01:35 +01:00
INSTALLED_APPS = [
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"kadenios.apps.IgnoreSrcStaticFilesConfig",
"background_task",
2021-05-29 09:11:19 +02:00
"shared",
2020-12-19 18:01:35 +01:00
"elections",
2021-06-15 11:41:04 +02:00
"faqs",
2021-01-26 14:26:35 +01:00
"authens",
2020-12-19 18:01:35 +01:00
]
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
2021-04-14 03:22:22 +02:00
"django.middleware.locale.LocaleMiddleware",
2020-12-19 18:01:35 +01:00
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]
ROOT_URLCONF = "kadenios.urls"
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
2021-05-29 09:11:19 +02:00
"DIRS": [],
2020-12-19 18:01:35 +01:00
"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 = "kadenios.wsgi.application"
2021-04-07 13:56:17 +02:00
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
DEFAULT_FROM_EMAIL = "Kadenios <cof-geek-sysadmin@ens.fr>"
2020-12-19 18:01:35 +01:00
# #############################################################################
# Paramètres d'authentification
# #############################################################################
2020-12-19 18:01:35 +01:00
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",
},
]
AUTH_USER_MODEL = "elections.User"
2020-12-21 00:07:07 +01:00
AUTHENTICATION_BACKENDS = [
2021-01-26 14:26:35 +01:00
"shared.auth.backends.PwdBackend",
"shared.auth.backends.CASBackend",
2020-12-21 00:07:07 +01:00
"shared.auth.backends.ElectionBackend",
]
2021-01-26 14:26:35 +01:00
LOGIN_URL = reverse_lazy("authens:login")
LOGIN_REDIRECT_URL = "/"
AUTHENS_USE_OLDCAS = False
2020-12-19 18:01:35 +01:00
# #############################################################################
# Paramètres de langage
# #############################################################################
2020-12-19 18:01:35 +01:00
LANGUAGE_CODE = "fr-fr"
TIME_ZONE = "Europe/Paris"
USE_I18N = True
USE_L10N = True
USE_TZ = True
2021-04-14 03:22:22 +02:00
LANGUAGES = [
("fr", _("Français")),
("en", _("Anglais")),
]
LOCALE_PATHS = [os.path.join(BASE_DIR, "shared", "locale")]
# #############################################################################
# Paramètres des fichiers statiques
# #############################################################################
2020-12-19 18:01:35 +01:00
STATIC_URL = "/static/"