text: # -*- encoding: utf-8 -*-
  """
  License: MIT
  Copyright (c) 2019 - present AppSeed.us
  """
  
  import os
  from decouple import config
  from unipath import Path
  import dj_database_url
  
  class IPList(list):
  
      def __init__(self, ips):
          try:
              #http://software.inl.fr/trac/wiki/IPy
              #ubuntu: apt-get install python-ipy
              from IPy import IP
              for ip in ips:
                  self.append(IP(ip))
          except ImportError:
              pass
              
      def __contains__(self, ip):
          try:
              for net in self:
                  if ip in net:
                      return True
          except:
              pass
          return False
  
  # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
  BASE_DIR    = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  PROJECT_DIR = Path(__file__).parent
  
  # Application definition
  
  INSTALLED_APPS = [
  
      # Generic
      'django.contrib.admin',
      'django.contrib.auth',
      'django.contrib.contenttypes',
      'django.contrib.sessions',
      'django.contrib.messages',
      'django.contrib.staticfiles',
  
      # Health Checks
      'health_check',                             # required
      #'health_check.db',                          # stock Django health checkers
      #'health_check.cache',
      'health_check.storage',
      #'health_check.contrib.migrations',
      #'health_check.contrib.celery',              # requires celery
      #'health_check.contrib.psutil',              # disk and memory utilization; requires psutil
      #'health_check.contrib.s3boto3_storage',     # requires boto3 and S3BotoStorage backend
      #'health_check.contrib.rabbitmq',            # requires RabbitMQ broker
      #'health_check.contrib.redis',               # required Redis broker
  
      "debug_toolbar",
  
      # Applications
      'app'  # Enable the inner app 
  ]
  
  HEALTH_CHECK = {
      'DISK_USAGE_MAX': 90,  # percent
      'MEMORY_MIN': 100,    # in MB
  }
  
  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',
      'whitenoise.middleware.WhiteNoiseMiddleware',
      'debug_toolbar.middleware.DebugToolbarMiddleware',
  ]
  
  INTERNAL_IPS = IPList([
      '127.0.0.1',
      '10.0.0.0/8',
      '172.16.0.0/12',
      '192.168.0.0/16',
      '169.254.0.0/16'
  ])
  
  DEBUG_TOOLBAR_PANELS = [
      'debug_toolbar.panels.versions.VersionsPanel',
      'debug_toolbar.panels.timer.TimerPanel',
      'debug_toolbar.panels.settings.SettingsPanel',
      'debug_toolbar.panels.headers.HeadersPanel',
      'debug_toolbar.panels.request.RequestPanel',
      'debug_toolbar.panels.sql.SQLPanel',
      'debug_toolbar.panels.staticfiles.StaticFilesPanel',
      'debug_toolbar.panels.templates.TemplatesPanel',
      'debug_toolbar.panels.cache.CachePanel',
      'debug_toolbar.panels.signals.SignalsPanel',
      'debug_toolbar.panels.logging.LoggingPanel',
      'debug_toolbar.panels.redirects.RedirectsPanel',
      'debug_toolbar.panels.profiling.ProfilingPanel',
  ]
  
  ROOT_URLCONF = 'core.urls'
  LOGIN_REDIRECT_URL = "home"   # Route defined in app/urls.py
  LOGOUT_REDIRECT_URL = "home"  # Route defined in app/urls.py
  TEMPLATE_DIR = os.path.join(BASE_DIR, "core/templates")  # ROOT dir for templates
  
  TEMPLATES = [
      {
          'BACKEND': 'django.template.backends.django.DjangoTemplates',
          'DIRS': [TEMPLATE_DIR],
          '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 = 'core.wsgi.application'
  
  # Database
  # https://docs.djangoproject.com/en/3.0/ref/settings/#databases
  
  # 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',
      },
  ]
  
  
  # 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
  
  #############################################################
  # SRC: https://devcenter.heroku.com/articles/django-assets
  
  BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  
  # Static files (CSS, JavaScript, Images)
  # https://docs.djangoproject.com/en/1.9/howto/static-files/
  STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
  STATIC_URL = '/static/'
  
  # Extra places for collectstatic to find static files.
  STATICFILES_DIRS = (
      os.path.join(BASE_DIR, 'core/static'),
  )
  
  # Settings profile selection
  DJANGO_SETTINGS_PROFILE=config('DJANGO_SETTINGS_PROFILE', default='local')
  if DJANGO_SETTINGS_PROFILE == 'local':
      # No cloud access, local execution
      from .settings_local import *
  elif DJANGO_SETTINGS_PROFILE == 'cloud':
      # Cloud access, SSM usage
      from .settings_cloud import *
  else:
      # Default is local
      from .settings_local import *
  
  
  #############################################################
  #############################################################
  