text: """
  Django settings for pelotourney 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
  
  import dj_database_url
  import structlog
  from django.urls import reverse_lazy
  from dotenv import load_dotenv
  
  
  def getenv_bool(envvar: str, default: bool = False) -> bool:
      val = os.getenv(envvar)
      if not val or not envvar.strip():
          return default
      elif val.strip().lower() in {"1", "on", "yes", "t", "true"}:
          return True
      elif val.strip().lower() in {"0", "off", "no", "f", "false"}:
          return False
      else:
          raise ValueError(f"Unable to parse value as boolean: {envvar}={val!r}")
  
  
  # Build paths inside the project like this: BASE_DIR / 'subdir'.
  BASE_DIR = Path(__file__).resolve().parent.parent
  
  # Load environment varibles from any `.env` files
  load_dotenv(os.path.join(BASE_DIR, ".env"))
  
  # Quick-start development settings - unsuitable for production
  # See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
  
  # SECURITY WARNING: don't run with debug turned on in production!
  ENVIRONMENT = os.getenv("ENVIRONMENT", "dev")
  DEBUG = getenv_bool("DEBUG", True if ENVIRONMENT == "dev" else False)
  
  # Django Debug Toolbar
  # Only enabled if (a) it's installed and (b) DEBUG is set
  DEBUG_TOOLBAR = getenv_bool("DEBUG_TOOLBAR", DEBUG)
  if DEBUG_TOOLBAR:
      try:
          import debug_toolbar
      except ImportError:
          debug_toolbar = False
  else:
      debug_toolbar = False
  
  if debug_toolbar:
      INTERNAL_IPS = ["127.0.0.1"]
  
  # SECURITY WARNING: keep the secret key used in production secret!
  SECRET_KEY = os.getenv("SECRET_KEY")
  
  ALLOWED_HOSTS = []
  DOMAIN = os.getenv("DOMAIN")
  if DOMAIN:
      ALLOWED_HOSTS.append(DOMAIN)
  
  
  # Application definition
  
  INSTALLED_APPS = [
      "django.contrib.admin",
      "django.contrib.auth",
      "django.contrib.contenttypes",
      "django.contrib.sessions",
      "django.contrib.messages",
      "django.contrib.staticfiles",
      "pelotourney",
      "tournaments",
      "social_django",
      "auth0login",
  ]
  if debug_toolbar:
      INSTALLED_APPS.append("debug_toolbar")
  
  MIDDLEWARE = [
      "django.middleware.security.SecurityMiddleware",
  ]
  if debug_toolbar:
      MIDDLEWARE.append("debug_toolbar.middleware.DebugToolbarMiddleware")
  MIDDLEWARE.extend(
      [
          "whitenoise.middleware.WhiteNoiseMiddleware",
          "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_structlog.middlewares.RequestMiddleware",
      ]
  )
  
  ROOT_URLCONF = "pelotourney.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",
              ],
          },
      },
  ]
  
  WSGI_APPLICATION = "pelotourney.wsgi.application"
  
  
  # Database
  # https://docs.djangoproject.com/en/3.2/ref/settings/#databases
  DATABASE_URL = os.getenv(
      "DATABASE_URL", "postgresql://postgres@127.0.0.1:5432/pelotourney"
  )
  CONN_MAX_AGE = int(os.getenv("DATABASE_CONN_MAX_AGE", "0"))
  DATABASES = {"default": dj_database_url.parse(DATABASE_URL, conn_max_age=CONN_MAX_AGE)}
  
  
  # Password validation
  # https://docs.djangoproject.com/en/3.2/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",
      },
  ]
  
  
  # Internationalization
  # https://docs.djangoproject.com/en/3.2/topics/i18n/
  
  LANGUAGE_CODE = "en-us"
  
  TIME_ZONE = "UTC"
  
  USE_I18N = True
  
  USE_L10N = True
  
  USE_TZ = True
  
  
  # Static files (CSS, JavaScript, Images)
  # https://docs.djangoproject.com/en/3.2/howto/static-files/
  # http://whitenoise.evans.io/en/stable/
  
  STATIC_URL = "/static/"
  STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")
  STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
  
  # Default primary key field type
  # https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
  
  DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
  
  LOGGING = {
      "version": 1,
      "disable_existing_loggers": False,
      "formatters": {
          "json_formatter": {
              "()": structlog.stdlib.ProcessorFormatter,
              "processor": structlog.processors.JSONRenderer(),
          },
          "plain_console": {
              "()": structlog.stdlib.ProcessorFormatter,
              "processor": structlog.dev.ConsoleRenderer(),
          },
          "key_value": {
              "()": structlog.stdlib.ProcessorFormatter,
              "processor": structlog.processors.KeyValueRenderer(
                  key_order=["timestamp", "level", "event", "logger"]
              ),
          },
      },
      "handlers": {
          "console": {
              "class": "logging.StreamHandler",
              "formatter": "plain_console",
          },
          "json": {
              "class": "logging.StreamHandler",
              "formatter": "json_formatter",
          },
      },
      "loggers": {
          "django": {
              "handlers": ["console"],
              "propagate": True,
              "level": "INFO",
          },
          "tournaments": {
              "handlers": ["console"],
              "propagate": True,
              "level": "INFO",
          },
          "django_structlog": {
              "handlers": ["console"],
              "level": "INFO",
          },
      },
  }
  
  structlog.configure(
      processors=[
          structlog.stdlib.filter_by_level,
          structlog.processors.TimeStamper(fmt="iso"),
          structlog.stdlib.add_logger_name,
          structlog.stdlib.add_log_level,
          structlog.stdlib.PositionalArgumentsFormatter(),
          structlog.processors.StackInfoRenderer(),
          structlog.processors.format_exc_info,
          structlog.processors.UnicodeDecoder(),
          structlog.stdlib.ProcessorFormatter.wrap_for_formatter,
      ],
      context_class=structlog.threadlocal.wrap_dict(dict),
      logger_factory=structlog.stdlib.LoggerFactory(),
      wrapper_class=structlog.stdlib.BoundLogger,
      cache_logger_on_first_use=True,
  )
  
  # Setting up login and redirect URLs
  LOGIN_URL = reverse_lazy("social:begin", kwargs={"backend": "auth0"})
  LOGIN_REDIRECT_URL = "/"
  
  # Social auth
  SOCIAL_AUTH_AUTH0_DOMAIN = os.getenv("SOCIAL_AUTH_AUTH0_DOMAIN")
  SOCIAL_AUTH_AUTH0_KEY = os.getenv("SOCIAL_AUTH_AUTH0_KEY")
  SOCIAL_AUTH_AUTH0_SECRET = os.getenv("SOCIAL_AUTH_AUTH0_SECRET")
  SOCIAL_AUTH_AUTH0_SCOPE = ["openid", "profile", "email"]
  
  AUTHENTICATION_BACKENDS = {
      "auth0login.auth0backend.Auth0",
      "django.contrib.auth.backends.ModelBackend",
  }
  
  # SSL Redirect
  if ENVIRONMENT == "prod":
      SECURE_SSL_REDIRECT = os.getenv("SECURE_SSL_REDIRECT", True)
      SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
  