""" Django settings for the kadenios project """ from pathlib import Path from loadcredential import Credentials from django.urls import reverse_lazy from django.utils.translation import gettext_lazy as _ credentials = Credentials(env_prefix="KADENIOS_") # 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 = [ "django.contrib.admin", "django.contrib.auth", "django.contrib.contenttypes", "django.contrib.sessions", "django.contrib.messages", "shared.IgnoreSrcStaticFilesConfig", "background_task", "shared", "elections", "faqs", "authens", ] ### # 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", ] ### # The main url configuration ROOT_URLCONF = "app.urls" ### # Template configuration: # - Django Templating Language is used # - Application directories can be used 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" ### # E-Mail configuration DEFAULT_FROM_EMAIL = credentials["FROM_EMAIL"] EMAIL_HOST = credentials.get("EMAIL_HOST", "localhost") EMAIL_HOST_PASSWORD = credentials.get("EMAIL_HOST_PASSWORD", "") EMAIL_HOST_USER = credentials.get("EMAIL_HOST_USER", "") EMAIL_USE_SSL = credentials.get("EMAIL_USE_SSL", False) SERVER_EMAIL = credentials["SERVER_EMAIL"] ### # Default primary key field type # -> https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field DEFAULT_AUTO_FIELD = "django.db.models.AutoField" ### # 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 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" AUTHENTICATION_BACKENDS = [ "shared.auth.backends.PwdBackend", "shared.auth.backends.CASBackend", "shared.auth.backends.ElectionBackend", ] LOGIN_URL = reverse_lazy("authens:login") LOGIN_REDIRECT_URL = "/" AUTHENS_USE_OLDCAS = False ### # Internationalization configuration # -> https://docs.djangoproject.com/en/4.2/topics/i18n/ LANGUAGE_CODE = "fr-fr" TIME_ZONE = "Europe/Paris" USE_I18N = True USE_L10N = True USE_TZ = True LANGUAGES = [ ("fr", _("Français")), ("en", _("Anglais")), ] LOCALE_PATHS = [BASE_DIR / "shared" / "locale"] ### # Static files (CSS, JavaScript, Images) configuration # -> https://docs.djangoproject.com/en/4.2/howto/static-files/ STATIC_URL = "/static/" STATIC_ROOT = credentials["STATIC_ROOT"] ### # Background tasks configuration # -> https://django4-background-tasks.readthedocs.io/en/latest/#settings BACKGROUND_TASK_RUN_ASYNC = True BACKGROUND_TASK_ASYNC_THREADS = 4 if DEBUG: # Print the e-mails in the console EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend" INSTALLED_APPS += [ "debug_toolbar", "django_browser_reload", ] MIDDLEWARE += [ "debug_toolbar.middleware.DebugToolbarMiddleware", "django_browser_reload.middleware.BrowserReloadMiddleware", ] INTERNAL_IPS = ["127.0.0.1"] DEBUG_TOOLBAR_CONFIG = {"INSERT_BEFORE": ""}