text: """
  Django settings for levechad project.
  
  Generated by 'django-admin startproject' using Django 3.0.4.
  
  For more information on this file, see
  https://docs.djangoproject.com/en/3.0/topics/settings/
  
  For the full list of settings and their values, see
  https://docs.djangoproject.com/en/3.0/ref/settings/
  """
  
  import os
  from enum import Enum
  
  # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
  
  BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  ENV = os.environ.get('ENV', 'DEVELOPMENT')
  
  # Quick-start development settings - unsuitable for production
  # See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
  
  # SECURITY WARNING: keep the secret key used in production secret!
  if ENV == 'PRODUCTION':
      SECRET_KEY = os.environ.get('SECRET_KEY')
  else:
      SECRET_KEY = 'MYSECRET'
  
  # SECURITY WARNING: don't run with debug turned on in production!
  if ENV == 'PRODUCTION':
      DEBUG = False
  else:
      DEBUG = True
  
  ALLOWED_HOSTS = ['*']
  
  FRONTEND_BASE_URI = os.environ.get('FRONTEND_URI',
                                     'https://corona.levechad.org' if ENV == 'PRODUCTION'
                                     else 'https://devfe.levechad.org')
  
  FRONTEND_SECONDARY_URI = os.environ.get("FRONTEND_URI_SECONDARY", None)
  
  # Application definition
  
  IMPORT_EXPORT_USE_TRANSACTIONS = True
  
  INSTALLED_APPS = [
      'client.apps.ClientConfig',
      'server.apps.ServerConfig',
      'api.apps.ApiConfig',
      'django.contrib.admin',
      'django.contrib.auth',
      'django.contrib.contenttypes',
      'django.contrib.sessions',
      'django.contrib.messages',
      'django.contrib.staticfiles',
      'bootstrapform',
      'mathfilters',
      'storages',
      'django_extensions',
      'rest_framework',
      'rest_framework.authtoken',
      'corsheaders',
      'django_filters',
      'import_export',
      'drf_yasg',
  
  ]
  
  MIDDLEWARE = [
      'django.middleware.security.SecurityMiddleware',
      'django.contrib.sessions.middleware.SessionMiddleware',
      'corsheaders.middleware.CorsMiddleware',
      'django.middleware.common.CommonMiddleware',
      'django.middleware.csrf.CsrfViewMiddleware',
      'django.contrib.auth.middleware.AuthenticationMiddleware',
      'django.contrib.messages.middleware.MessageMiddleware',
      'django.middleware.clickjacking.XFrameOptionsMiddleware',
  ]
  
  CORS_URLS_REGEX = r'^/api/.*$'
  if ENV == 'DEVELOPMENT' or ENV == 'TESTING':
      CORS_ORIGIN_ALLOW_ALL = True
  else:
      # TODO fill with deployment address when it's created (#267)
      CORS_ORIGIN_WHITELIST = [FRONTEND_BASE_URI]
      if FRONTEND_SECONDARY_URI is not None:
          CORS_ORIGIN_WHITELIST.append(FRONTEND_SECONDARY_URI)
  
  ROOT_URLCONF = 'levechad.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 = 'levechad.wsgi.application'
  
  # Database
  # https://docs.djangoproject.com/en/3.0/ref/settings/#databases
  if 'RDS_HOSTNAME' in os.environ:
      DATABASES = {
          'default': {
              'ENGINE': 'django.db.backends.postgresql',
              'NAME': os.environ['RDS_DB_NAME'],
              'USER': os.environ['RDS_USERNAME'],
              'PASSWORD': os.environ['RDS_PASSWORD'],
              'HOST': os.environ['RDS_HOSTNAME'],
              'PORT': os.environ['RDS_PORT'],
          }
      }
  else:
      DATABASES = {
          'default': {
              'ENGINE': 'django.db.backends.sqlite3',
              'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
          }
      }
  
  # Password validation
  # https://docs.djangoproject.com/en/3.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',
      },
  ]
  if ENV in ('DEVELOPMENT', 'TESTING') and os.environ.get('ENABLE_LOGGING', '') == 'TRUE':
      LOGGING = {
          'version': 1,
          'disable_existing_loggers': False,
          'handlers': {
              'file': {
                  'level': 'DEBUG',
                  'class': 'logging.FileHandler',
                  'filename': 'lev-debug.log',
              },
              'console': {
                  'class': 'logging.StreamHandler',
              },
          },
          'loggers': {
              'django': {
                  'handlers': ['file', 'console'],
                  'propagate': True,
                  'level': os.getenv('DJANGO_LOG_LEVEL', 'DEBUG')
              },
          },
      }
  
  # Internationalization
  # https://docs.djangoproject.com/en/3.0/topics/i18n/
  
  LANGUAGE_CODE = 'en-us'
  
  # TIME_ZONE = 'UTC'
  
  USE_I18N = True
  
  USE_L10N = True
  
  USE_TZ = True
  TIME_ZONE = "Asia/Jerusalem"
  
  LOGIN_REDIRECT_URL = '/server'
  
  # Static files (CSS, JavaScript, Images)
  # https://docs.djangoproject.com/en/3.0/howto/static-files/
  STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
  MEDIA_ROOT = os.path.join(BASE_DIR, 'mediafiles')
  
  if ENV == 'PRODUCTION' or ENV == 'TESTING':
      # Redirect http request to https
      SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
      SECURE_SSL_REDIRECT = True
  
      # In production, use S3 to serve static & media files
      AWS_ACCESS_KEY_ID = os.getenv('AWS_ACCESS_KEY_ID')
      AWS_SECRET_ACCESS_KEY = os.getenv('AWS_SECRET_ACCESS_KEY')
      AWS_STORAGE_BUCKET_NAME = os.getenv('AWS_STORAGE_BUCKET_NAME')
  
      AWS_DEFAULT_ACL = None
      AWS_S3_CUSTOM_DOMAIN = f'{AWS_STORAGE_BUCKET_NAME}.s3.amazonaws.com'
      AWS_S3_OBJECT_PARAMETERS = {'CacheControl': 'max-age=86400'}
  
      # s3 static settings
      STATIC_LOCATION = 'static'
      STATIC_URL = f'https://{AWS_S3_CUSTOM_DOMAIN}/{STATIC_LOCATION}/'
      STATICFILES_STORAGE = 'levechad.storage_backends.StaticStorage'
  
      # s3 public media settings
      PUBLIC_MEDIA_LOCATION = 'media'
      MEDIA_URL = f'https://{AWS_S3_CUSTOM_DOMAIN}/{PUBLIC_MEDIA_LOCATION}/'
      DEFAULT_FILE_STORAGE = 'levechad.storage_backends.PublicMediaStorage'
  else:
      # In development, let django serve static files (and media files in urls.py)
      STATIC_URL = '/static/'
      MEDIA_URL = '/media/'
  
  # Django Rest Framework configuration
  _renderer_classes = ['rest_framework.renderers.JSONRenderer']
  if ENV != 'PRODUCTION':
      _renderer_classes += ['rest_framework.renderers.BrowsableAPIRenderer']
  
  REST_FRAMEWORK = {
      'DEFAULT_RENDERER_CLASSES': _renderer_classes,
      'DEFAULT_PAGINATION_CLASS': 'api.pagination.DefaultPagination',
      'DEFAULT_AUTHENTICATION_CLASSES': [
          'rest_framework.authentication.TokenAuthentication',
      ],
      'DEFAULT_FILTER_BACKENDS': ('django_filters.rest_framework.DjangoFilterBackend',),
      'DEFAULT_THROTTLE_RATES': {
          'hamal-data': '5/second',
          'login': '1/second',
          'user-choices-list': '5/second',
          'city-autocomplete': '3/second',
          'register': '',  # overridden in throttling.py
          'send-sms': '',  # overridden in throttling.py
          'check-sms': '',  # overridden in throttling.py
      },
  }
  # Add extra authentication option to support swagger. Removed from PROD to keep minimal surface.
  if ENV != "PRODUCTION":
      REST_FRAMEWORK['DEFAULT_AUTHENTICATION_CLASSES'].append('rest_framework.authentication.SessionAuthentication')
  
  
  # Geocoding settings
  class LocatorTypes(Enum):
      NOMINATIM = 1
      GOOGLE = 2
      ARCGIS = 3
  
  
  LOCATOR = LocatorTypes.NOMINATIM
  GOOGLE_API_SECRET_KEY = os.environ.get('GOOGLE_API_KEY', default=None)
  
  SWAGGER_SETTINGS = {
      'SECURITY_DEFINITIONS': {
          'DRF Token': {
              'type': 'apiKey',
              'name': 'Authorization',
              'in': 'header'
          }
      }
  }
  
  # Volunteer certificate settings
  CERTIFICATE_TEXT_COLOR = (3, 8, 12)  # (R, G, B)
  CERTIFICATE_TEXT_SIZE = 40
  CERTIFICATE_TEXT_POSITION = (700, 200)
  CERTIFICATE_IMAGE_PATH = 'certificates/{filename}.png'
  CERTIFICATE_DOWNLOAD_LINK_EXPIRATION_SECONDS = 600
  