""" Django settings For more information on this file, see https://docs.djangoproject.com/en/2.0/topics/settings/ For the full list of settings and their values, see https://docs.djangoproject.com/en/2.0/ref/settings/ """ import os from os.path import dirname, normpath, join from .app_settings import * # noqa: F403, F401 # We need to load app specific settings import sys #################################### # # Directory locations # #################################### BACKEND_ROOT_DIR = dirname(dirname(dirname(os.path.abspath(__file__)))) REPO_ROOT_DIR = dirname(BACKEND_ROOT_DIR) # # ##################################### # # Django essential settings # ##################################### SECRET_KEY = os.environ["SECRET_KEY"] ROOT_URLCONF = "base_app.urls" WSGI_APPLICATION = "base_app.wsgi.application" STATIC_URL = "/static/" STATIC_ROOT = normpath(join(BACKEND_ROOT_DIR, "static")) MEDIA_ROOT = normpath(join(BACKEND_ROOT_DIR, "media")) MEDIA_URL = "/media/" # # ##################################### # # Sub-applications in the app # ##################################### INSTALLED_APPS = [ "django.contrib.admin", "django.contrib.auth", "django.contrib.contenttypes", "django.contrib.sessions", "django.contrib.messages", "django.contrib.staticfiles", "django_cas_ng", "reversion", "reversion_compare", "rest_framework", "rest_framework.authtoken", "backend_app", "base_app", "webpack_loader", ] # # ##################################### # # Rest framework configuration # ##################################### REST_FRAMEWORK = { # Use Django's standard `django.contrib.auth` permissions, "DEFAULT_PERMISSION_CLASSES": ( "rest_framework.permissions.DjangoModelPermissions", ), "DEFAULT_AUTHENTICATION_CLASSES": ( "rest_framework.authentication.SessionAuthentication", "rest_framework.authentication.TokenAuthentication", ), } # # ##################################### # # Webpack loader config to enable frontend hot module replacement # ##################################### WEBPACK_LOADER = { "DEFAULT": { "BUNDLE_DIR_NAME": "base_app/frontend_dist/bundles/", "STATS_FILE": join(REPO_ROOT_DIR, "frontend/webpack-stats.json"), } } # # ##################################### # # Middlewares applied to the request # ##################################### 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", "base_app.middleware.LoginRequiredMiddleware", ] # # ##################################### # # Big variables settings # ##################################### if os.environ["ENV"] == "DEV": DEBUG = True ALLOWED_HOSTS = ["*"] INSTALLED_APPS += ["django_extensions", "debug_toolbar"] MIDDLEWARE = ["debug_toolbar.middleware.DebugToolbarMiddleware"] + MIDDLEWARE # Force the debug toolbar to be shown DEBUG_TOOLBAR_CONFIG = {"SHOW_TOOLBAR_CALLBACK": "base_app.utils.show_toolbar"} else: DEBUG = False TESTING = "pytest" in sys.modules # # ##################################### # # Authentication related # ##################################### # Use a custom User model for optimization AUTH_USER_MODEL = "base_app.User" AUTHENTICATION_BACKENDS = [ "django.contrib.auth.backends.ModelBackend", "django_cas_ng.backends.CASBackend", ] # Password validation # https://docs.djangoproject.com/en/2.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"}, ] LOGIN_URL = "/user/login" LOGIN_EXEMPT_URLS = [LOGIN_URL, "/admin/"] if TESTING: # In a testing environment we want to by pass the loginRequiredMiddleware LOGIN_EXEMPT_URLS.append("api") SESSION_EXPIRE_AT_BROWSER_CLOSE = True # # ##################################### # # Django Templating settings # ##################################### 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", ] }, } ] # # ##################################### # # Database configuration # ##################################### # https://docs.djangoproject.com/en/2.0/ref/settings/#databases DATABASES = { "default": { "ENGINE": "django.db.backends.postgresql_psycopg2", "NAME": os.environ["POSTGRES_DB"], "USER": os.environ["POSTGRES_USER"], "PASSWORD": os.environ["POSTGRES_PASSWORD"], "HOST": os.environ["DB_HOST"], "PORT": os.environ["DB_PORT"], } } # To use Sqlite, uncomment below and comment above # DATABASES = { # "default": { # "ENGINE": "django.db.backends.sqlite3", # "NAME": join(BACKEND_ROOT_DIR, "./database.db"), # } # } # # ##################################### # # Internationalization # ##################################### # https://docs.djangoproject.com/en/2.0/topics/i18n/ LANGUAGE_CODE = "fr-fr" TIME_ZONE = "Europe/Paris" USE_I18N = True USE_L10N = True USE_TZ = True