text: """
  Django settings for field project.
  
  For the full list of settings and their values, see
  https://docs.djangoproject.com/en/dev/ref/settings/
  
  For production settings see
  https://docs.djangoproject.com/en/dev/howto/deployment/checklist/
  """
  
  import getpass
  import logging
  import os
  
  from django_auth_ldap.config import LDAPGroupQuery
  from kdl_ldap.settings import *  # noqa
  
  
  # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
  BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
  
  PROJECT_NAME = 'field'
  PROJECT_TITLE = 'FIELD'
  
  # -----------------------------------------------------------------------------
  # Core Settings
  # https://docs.djangoproject.com/en/dev/ref/settings/#id6
  # -----------------------------------------------------------------------------
  
  ADMINS = ()
  MANAGERS = ADMINS
  
  ALLOWED_HOSTS = []
  
  # https://docs.djangoproject.com/en/dev/ref/settings/#caches
  # https://docs.djangoproject.com/en/dev/topics/cache/
  # http://redis.io/topics/lru-cache
  # http://niwibe.github.io/django-redis/
  CACHE_REDIS_DATABASE = '0'
  
  CACHES = {
      'default': {
          'BACKEND': 'django_redis.cache.RedisCache',
          'LOCATION': 'redis://127.0.0.1:6379/' + CACHE_REDIS_DATABASE,
          'OPTIONS': {
              'CLIENT_CLASS': 'django_redis.client.DefaultClient',
              'IGNORE_EXCEPTIONS': True
          }
      }
  }
  
  CSRF_COOKIE_SECURE = True
  
  # SECURITY WARNING: don't run with debug turned on in production!
  DEBUG = False
  
  # -----------------------------------------------------------------------------
  # EMAIL SETTINGS
  # -----------------------------------------------------------------------------
  
  DEFAULT_FROM_EMAIL = 'noreply@kcl.ac.uk'
  EMAIL_HOST = 'smtp.cch.kcl.ac.uk'
  EMAIL_PORT = 25
  EMAIL_HOST_USER = ''
  EMAIL_HOST_PASSWORD = ''
  EMAIL_SUBJECT_PREFIX = '[Django {}] '.format(PROJECT_NAME)
  EMAIL_USE_TLS = False
  
  # Sender of error messages to ADMINS and MANAGERS
  SERVER_EMAIL = DEFAULT_FROM_EMAIL
  
  INSTALLED_APPS = [
      'django.contrib.admin',
      'django.contrib.auth',
      'django.contrib.contenttypes',
      'django.contrib.sessions',
      'django.contrib.messages',
      'django.contrib.staticfiles',
      'django_extensions',
      'compressor',
  ]
  
  INSTALLED_APPS += [  # your project apps here
      'kdl_ldap',
      'rest_framework',
  
      'wagtail.core',
      'wagtail.admin',
      'wagtail.documents',
      'wagtail.snippets',
      'wagtail.users',
      'wagtail.images',
      'wagtail.embeds',
      'wagtail.contrib.redirects',
      'wagtail.contrib.forms',
      'wagtail.sites',
      'wagtail.contrib.routable_page',
      'wagtail.contrib.table_block',
      'taggit',
      'modelcluster',
      'wagtail.search',
      'wagtail.contrib.modeladmin',
      'wagtailmenus',
  
      'kdl_wagtail_page',
      'controlled_vocabulary',
      'dublincore_resource',
      'wagtail.contrib.sitemaps', # ?
      'django_social_share', # ?
      'puput',
      'colorful', # unused?
      'wagtail.contrib.settings',
      'kdl_wagtail.core',
      'kdl_wagtail.people',
      'field_timeline',
      'django_kdl_timeline',
      'field_wagtail',
      'captcha', # ?
  ]
  
  
  #
  
  INTERNAL_IPS = ['127.0.0.1']
  
  # https://docs.djangoproject.com/en/dev/topics/i18n/
  LANGUAGE_CODE = 'en-gb'
  TIME_ZONE = 'Europe/London'
  USE_I18N = True
  USE_L10N = False
  USE_TZ = True
  
  LOGGING_ROOT = os.path.join(BASE_DIR, 'logs')
  LOGGING_LEVEL = logging.WARN
  
  if not os.path.exists(LOGGING_ROOT):
      os.makedirs(LOGGING_ROOT)
  
  LOGGING = {
      'version': 1,
      'disable_existing_loggers': False,
      'formatters': {
          'verbose': {
              'format': ('%(levelname)s %(asctime)s %(module)s '
                         '%(process)d %(thread)d %(message)s')
          },
          'simple': {
              'format': '%(levelname)s %(message)s'
          }
      },
      'handlers': {
          'file': {
              'level': 'DEBUG',
              'class': 'logging.handlers.TimedRotatingFileHandler',
              'filename': os.path.join(LOGGING_ROOT, 'django.log'),
              'formatter': 'verbose'
          },
          'console': {
              'level': 'DEBUG',
              'class': 'logging.StreamHandler',
              'formatter': 'simple'
          },
          'mail_admins': {
              'level': 'ERROR',
              'class': 'django.utils.log.AdminEmailHandler'
          }
      },
      'loggers': {
          'django': {
              'handlers': ['file', 'mail_admins'],
              'level': LOGGING_LEVEL,
              'propagate': True
          },
          'field': {
              'handlers': ['file'],
              'level': LOGGING_LEVEL,
              'propagate': True
          },
          'elasticsearch': {
              'handlers': ['file'],
              'level': LOGGING_LEVEL,
              'propagate': True
          },
      }
  }
  
  MIDDLEWARE = [
      '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.security.SecurityMiddleware',
      'django.middleware.clickjacking.XFrameOptionsMiddleware',
  
      'wagtail.core.middleware.SiteMiddleware',
      'wagtail.contrib.redirects.middleware.RedirectMiddleware',
  
  ]
  
  ROOT_URLCONF = PROJECT_NAME + '.urls'
  
  # SECURITY WARNING: keep the secret key used in production secret!
  SECRET_KEY = ''
  
  TEMPLATES = [
      {
          'BACKEND': 'django.template.backends.django.DjangoTemplates',
          'DIRS': [os.path.join(BASE_DIR, 'templates')],
          'APP_DIRS': True,
          'OPTIONS': {
              'context_processors': [
                  'django.contrib.auth.context_processors.auth',
                  'django.template.context_processors.debug',
                  'django.template.context_processors.media',
                  'django.template.context_processors.request',
                  'django.template.context_processors.static',
                  'django.contrib.messages.context_processors.messages',
                  'wagtailmenus.context_processors.wagtailmenus',
                  'field_wagtail.context_processor.project_settings',
                  'field_wagtail.context_processor.mailing_list_footer',
              ],
          },
      },
  ]
  
  WSGI_APPLICATION = PROJECT_NAME + '.wsgi.application'
  
  # -----------------------------------------------------------------------------
  # Authentication
  # https://docs.djangoproject.com/en/dev/ref/settings/#auth
  # -----------------------------------------------------------------------------
  
  if 'wagtail.core' in INSTALLED_APPS:
      LOGIN_URL = '/wagtail/login/'
  else:
      LOGIN_URL = '/admin/login/'
  
  # -----------------------------------------------------------------------------
  # Sessions
  # https://docs.djangoproject.com/en/dev/ref/settings/#sessions
  # -----------------------------------------------------------------------------
  
  SESSION_COOKIE_SECURE = True
  
  # -----------------------------------------------------------------------------
  # Static files (CSS, JavaScript, Images)
  # https://docs.djangoproject.com/en/dev/howto/static-files/
  # https://docs.djangoproject.com/en/dev/ref/settings/#static-files
  # -----------------------------------------------------------------------------
  
  STATIC_URL = '/static/'
  STATIC_ROOT = os.path.join(BASE_DIR, STATIC_URL.strip('/'))
  
  if not os.path.exists(STATIC_ROOT):
      os.makedirs(STATIC_ROOT)
  
  STATICFILES_DIRS = (
      os.path.join(BASE_DIR, 'assets'),
      os.path.join(BASE_DIR, 'node_modules'),
  )
  
  STATICFILES_FINDERS = (
      'django.contrib.staticfiles.finders.FileSystemFinder',
      'django.contrib.staticfiles.finders.AppDirectoriesFinder',
      'compressor.finders.CompressorFinder',
  )
  
  MEDIA_URL = '/media/'
  MEDIA_ROOT = os.path.join(BASE_DIR, MEDIA_URL.strip('/'))
  
  if not os.path.exists(MEDIA_ROOT):
      os.makedirs(MEDIA_ROOT)
  
  # -----------------------------------------------------------------------------
  # Installed Applications Settings
  # -----------------------------------------------------------------------------
  
  # -----------------------------------------------------------------------------
  # Django Compressor
  # http://django-compressor.readthedocs.org/en/latest/
  # -----------------------------------------------------------------------------
  
  COMPRESS_ENABLED = True
  
  COMPRESS_CSS_FILTERS = [
      # CSS minimizer
      'compressor.filters.cssmin.CSSMinFilter'
  ]
  
  COMPRESS_PRECOMPILERS = (
      ('text/x-scss', 'django_libsass.SassCompiler'),
  )
  
  # -----------------------------------------------------------------------------
  # FABRIC
  # -----------------------------------------------------------------------------
  
  FABRIC_USER = getpass.getuser()
  USE_PIPENV = True
  
  # -----------------------------------------------------------------------------
  # GLOBALS FOR JS
  # -----------------------------------------------------------------------------
  
  # Google Analytics ID
  GA_ID = 'UA-67707155-9'
  
  # -----------------------------------------------------------------------------
  # Putput
  # -----------------------------------------------------------------------------
  
  PUPUT_AS_PLUGIN = True
  
  # -----------------------------------------------------------------------------
  # Automatically generated settings
  # -----------------------------------------------------------------------------
  
  # Check which db engine to use:
  db_engine = 'django.db.backends.postgresql_psycopg2'
  if 'django.contrib.gis' in INSTALLED_APPS:
      db_engine = 'django.contrib.gis.db.backends.postgis'
  
  AUTH_LDAP_REQUIRE_GROUP = (
      (
          LDAPGroupQuery(
              'cn=kdl-staff,' + LDAP_BASE_OU
          ) | LDAPGroupQuery(
              'cn=field,' + LDAP_BASE_OU
          )
      )
  )
  WAGTAIL_SITE_NAME = PROJECT_TITLE
  ITEMS_PER_PAGE = 10
  WAGTAILSEARCH_BACKENDS = {
      'default': {
          'BACKEND': 'wagtail.search.backends.elasticsearch5',
          'AUTO_UPDATE': False,
          'URLS': ['http://127.0.0.1:9200'],
          'INDEX': 'field_wagtail',
          'TIMEOUT': 5,
      }
  }
  
  #
  
  USE_BULMA = True
  
  # 1: root, 2: site home page, 3: top level page
  # default is 3, we change to 2 because our default main menu
  # is just the home page, nothing else.
  WAGTAILMENUS_SECTION_ROOT_DEPTH = 2
  
  # Note that KCL was (still is?) the research grant recipient.
  # Please make sure logo removal is agreed first with Wellcome & KCL.
  HIDE_KCL_LOGO = True
  
  # those settings vars will be available in template contexts
  SETTINGS_VARS_IN_CONTEXT = [
      'PROJECT_TITLE',
      'GA_ID',
      'USE_BULMA',
      'MAILING_LIST_FORM_WEB_PATH',
      'HIDE_KCL_LOGO',
  ]
  
  # slug of the page which is the parent of the specific communities
  FIELD_COMMUNITIES_ROOT_SLUG = 'groups'
  
  if 1:
      FABRIC_DEV_PACKAGES = [
          {
              'git': 'https://github.com/kingsdigitallab/django-kdl-wagtail.git',
              'folder_git': 'django-kdl-wagtail',
              'folder_package': 'kdl_wagtail',
              'branch': 'develop',
              'servers': ['lcl', 'dev', 'stg', 'liv'],
          }
      ]
  
  KDL_WAGTAIL_HIDDEN_PAGE_TYPES = [
      ('kdl_wagtail_page.richpage'),
      ('kdl_wagtail_core.streampage'),
      ('kdl_wagtail_core.indexpage'),
      ('kdl_wagtail_people.peopleindexpage'),
      ('kdl_wagtail_people.personpage'),
  ]
  
  MAILING_LIST_FORM_WEB_PATH = '/mailing-list/'
  
  # -----------------------------------------------------------------------------
  # Django Simple Captcha
  # -----------------------------------------------------------------------------
  
  CAPTCHA_FONT_SIZE = 36
  
  # Timeline settings
  
  TIMELINE_IMAGE_FOLDER = '/images/'
  TIMELINE_IMAGE_FORMAT = 'jpg'
  
  # dublin core settings
  # Set to True to disable the DublinCoreResource model and define your own
  DUBLINCORE_RESOURCE_ABSTRACT_ONLY = False
  
  # The path where resource file are uploaded, relative to your MEDIA path
  DUBLINCORE_RESOURCE_UPLOAD_PATH = 'uploads/dublin_core/'
  
  # ----------------------------------------------------------------------------
  # Wagtail extra settings
  # ----------------------------------------------------------------------------
  
  
  WAGTAILIMAGES_IMAGE_MODEL = "field_wagtail.FieldImage"
  