""" Django settings for drinks_manager project. Generated by 'django-admin startproject' using Django 3.2.5. For more information on this file, see https://docs.djangoproject.com/en/3.2/topics/settings/ For the full list of settings and their values, see https://docs.djangoproject.com/en/3.2/ref/settings/ """ import os from pathlib import Path # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key secret! django_secret_key_absolute_fp = os.environ["DJANGO_SK_ABS_FP"] with open(django_secret_key_absolute_fp) as secret_key_file: SECRET_KEY = secret_key_file.read().strip() # SECURITY WARNING: don't run with debug turned on in production! DEBUG = (os.environ["DJANGO_DEBUG"].lower() == "true") ALLOWED_HOSTS = [ "*" ] ### CSP Configuration ### CSP_DEFAULT_SRC = ("'self'", ) ### ----------------- ### # Application definition INSTALLED_APPS = [ "app.apps.DAppConfig", 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', ] 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_currentuser.middleware.ThreadLocalUserMiddleware", "csp.middleware.CSPMiddleware" ] ROOT_URLCONF = 'drinks_manager.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', "app.context_processors.app_version" ], }, }, ] WSGI_APPLICATION = 'drinks_manager.wsgi.application' # Database # https://docs.djangoproject.com/en/3.2/ref/settings/#databases DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': os.environ["PGDB_DB"], 'USER': os.environ["PGDB_USER"], 'PASSWORD': os.environ["PGDB_PASSWORD"], 'HOST': os.environ["PGDB_HOST"], 'PORT': str(os.environ["PGDB_PORT"]) } } CONN_MAX_AGE = 20 # keep database connections alive for n seconds # Password validation # https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators if os.environ["DJANGO_ENABLE_PASSWORD_VALIDATION"].lower() == "true": 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', }, ] else: AUTH_PASSWORD_VALIDATORS = [] AUTH_USER_MODEL = "app.User" # user will be logged out after x seconds SESSION_COOKIE_AGE = int(os.environ["DJANGO_SESSION_COOKIE_AGE"]) # more security settings CSRF_COOKIE_SECURE = True SESSION_COOKIE_SECURE = True # Internationalization # https://docs.djangoproject.com/en/3.2/topics/i18n/ LANGUAGE_CODE = os.environ["DJANGO_LANGUAGE_CODE"] # this is the default and fallback language (currently only de-de and en-us supported) TIME_ZONE = os.environ["DJANGO_TIME_ZONE"] USE_I18N = True USE_L10N = True USE_TZ = True LOCALE_PATHS = [ BASE_DIR / "locale" ] # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/3.2/howto/static-files/ STATIC_URL = '/static/' STATIC_ROOT = os.environ["STATIC_FILES"] # Default primary key field type # https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' # APP_VERSION = os.environ["APP_VERSION"] try: CURRENCY_SUFFIX = os.environ["CURRENCY_SUFFIX"] except KeyError: CURRENCY_SUFFIX = "$"