text: # -*- coding: utf-8 -*-
  """
  Django settings for Task Board project.
  
  For more information on this file, see
  https://docs.djangoproject.com/en/dev/topics/settings/
  
  For the full list of settings and their values, see
  https://docs.djangoproject.com/en/dev/ref/settings/
  """
  import environ
  
  ROOT_DIR = environ.Path(__file__) - 3  # (task_board/config/settings/base.py - 3 = task_board/)
  APPS_DIR = ROOT_DIR.path('task_board')
  
  BACKEND_DIR = ROOT_DIR
  FRONTEND_DIR = ROOT_DIR.path('frontend')
  
  # Load operating system environment variables and then prepare to use them
  env = environ.Env()
  
  # .env file, should load only in development environment
  READ_DOT_ENV_FILE = env.bool('DJANGO_READ_DOT_ENV_FILE', default=False)
  if READ_DOT_ENV_FILE:
      # Operating System Environment variables have precedence over variables defined in the .env file,
      # that is to say variables from the .env files will only be used if not defined
      # as environment variables.
      env_file = str(ROOT_DIR.path('.env'))
      print('Loading : {}'.format(env_file))
      env.read_env(env_file)
      print('The .env file has been loaded. See base.py for more information')
  
  # APP CONFIGURATION
  # ------------------------------------------------------------------------------
  DJANGO_APPS = [
      # Default Django apps:
      'django.contrib.auth',
      'django.contrib.contenttypes',
      'django.contrib.sessions',
      'django.contrib.sites',
      'django.contrib.messages',
  
      'whitenoise.runserver_nostatic',
      'django.contrib.staticfiles',
  
      # Useful template tags:
      # 'django.contrib.humanize',
  
      # Admin
      'django.contrib.admin',
  ]
  THIRD_PARTY_APPS = [
      'rest_framework',
      'django_filters',
  
      'crispy_forms',  # Form layouts
      'allauth',  # registration
      'allauth.account',  # registration
      'allauth.socialaccount',  # registration
  
      'bootstrap_pagination',
  ]
  
  # Apps specific for this project go here.
  LOCAL_APPS = [
      # custom users app
      'task_board.users.apps.UsersConfig',
      'task_board.tasks',
  ]
  
  # See: https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps
  INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS
  
  # MIDDLEWARE CONFIGURATION
  # ------------------------------------------------------------------------------
  MIDDLEWARE = [
      'django.middleware.security.SecurityMiddleware',
      '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',
  ]
  
  # MIGRATIONS CONFIGURATION
  # ------------------------------------------------------------------------------
  MIGRATION_MODULES = {
      'sites': 'task_board.contrib.sites.migrations'
  }
  
  # DEBUG
  # ------------------------------------------------------------------------------
  # See: https://docs.djangoproject.com/en/dev/ref/settings/#debug
  DEBUG = env.bool('DJANGO_DEBUG', False)
  
  # FIXTURE CONFIGURATION
  # ------------------------------------------------------------------------------
  # See: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-FIXTURE_DIRS
  FIXTURE_DIRS = (
      str(APPS_DIR.path('fixtures')),
  )
  
  # EMAIL CONFIGURATION
  # ------------------------------------------------------------------------------
  EMAIL_BACKEND = env('DJANGO_EMAIL_BACKEND', default='django.core.mail.backends.smtp.EmailBackend')
  
  # MANAGER CONFIGURATION
  # ------------------------------------------------------------------------------
  # See: https://docs.djangoproject.com/en/dev/ref/settings/#admins
  ADMINS = [
      ("""Alexander Kaluzhny""", 'alexander.kaluzhny@gmail.com'),
  ]
  
  # See: https://docs.djangoproject.com/en/dev/ref/settings/#managers
  MANAGERS = ADMINS
  
  # DATABASE CONFIGURATION
  # ------------------------------------------------------------------------------
  # See: https://docs.djangoproject.com/en/dev/ref/settings/#databases
  DATABASES = {
      'default': env.db('DATABASE_URL', default='postgres:///task_board'),
  }
  DATABASES['default']['ATOMIC_REQUESTS'] = True
  
  
  # GENERAL CONFIGURATION
  # ------------------------------------------------------------------------------
  # Local time zone for this installation. Choices can be found here:
  # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
  # although not all choices may be available on all operating systems.
  # In a Windows environment this must be set to your system time zone.
  TIME_ZONE = 'UTC'
  
  # See: https://docs.djangoproject.com/en/dev/ref/settings/#language-code
  LANGUAGE_CODE = 'en-us'
  
  # See: https://docs.djangoproject.com/en/dev/ref/settings/#site-id
  SITE_ID = 1
  
  # See: https://docs.djangoproject.com/en/dev/ref/settings/#use-i18n
  USE_I18N = True
  
  # See: https://docs.djangoproject.com/en/dev/ref/settings/#use-l10n
  USE_L10N = True
  
  # See: https://docs.djangoproject.com/en/dev/ref/settings/#use-tz
  USE_TZ = True
  
  # TEMPLATE CONFIGURATION
  # ------------------------------------------------------------------------------
  # See: https://docs.djangoproject.com/en/dev/ref/settings/#templates
  TEMPLATES = [
      {
          # See: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-TEMPLATES-BACKEND
          'BACKEND': 'django.template.backends.django.DjangoTemplates',
          # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-dirs
          'DIRS': [
              str(APPS_DIR.path('templates')),
              str(FRONTEND_DIR.path('build')),
          ],
          'OPTIONS': {
              # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-debug
              'debug': DEBUG,
              # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-loaders
              # https://docs.djangoproject.com/en/dev/ref/templates/api/#loader-types
              'loaders': [
                  'django.template.loaders.filesystem.Loader',
                  'django.template.loaders.app_directories.Loader',
              ],
              # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-context-processors
              'context_processors': [
                  'django.template.context_processors.debug',
                  'django.template.context_processors.request',
                  'django.contrib.auth.context_processors.auth',
                  'django.template.context_processors.i18n',
                  'django.template.context_processors.media',
                  'django.template.context_processors.static',
                  'django.template.context_processors.tz',
                  'django.contrib.messages.context_processors.messages',
              ],
          },
      },
  ]
  
  # See: http://django-crispy-forms.readthedocs.io/en/latest/install.html#template-packs
  CRISPY_TEMPLATE_PACK = 'bootstrap3'
  
  # STATIC FILE CONFIGURATION
  # ------------------------------------------------------------------------------
  # See: https://docs.djangoproject.com/en/dev/ref/settings/#static-root
  STATIC_ROOT = str(ROOT_DIR('staticfiles'))
  
  # See: https://docs.djangoproject.com/en/dev/ref/settings/#static-url
  STATIC_URL = '/static/'
  
  # See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#std:setting-STATICFILES_DIRS
  STATICFILES_DIRS = [
      str(APPS_DIR.path('static')),
      str(FRONTEND_DIR.path('build').path('static')),
  ]
  
  # Static Assets
  # ------------------------
  STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
  WHITENOISE_ROOT = str(FRONTEND_DIR.path('build').path('root'))
  
  # See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#staticfiles-finders
  STATICFILES_FINDERS = [
      'django.contrib.staticfiles.finders.FileSystemFinder',
      'django.contrib.staticfiles.finders.AppDirectoriesFinder',
  ]
  
  # MEDIA CONFIGURATION
  # ------------------------------------------------------------------------------
  # See: https://docs.djangoproject.com/en/dev/ref/settings/#media-root
  MEDIA_ROOT = str(APPS_DIR('media'))
  
  # See: https://docs.djangoproject.com/en/dev/ref/settings/#media-url
  MEDIA_URL = '/media/'
  
  # URL Configuration
  # ------------------------------------------------------------------------------
  ROOT_URLCONF = 'config.urls'
  
  # See: https://docs.djangoproject.com/en/dev/ref/settings/#wsgi-application
  WSGI_APPLICATION = 'config.wsgi.application'
  
  # PASSWORD STORAGE SETTINGS
  # ------------------------------------------------------------------------------
  # See https://docs.djangoproject.com/en/dev/topics/auth/passwords/#using-argon2-with-django
  PASSWORD_HASHERS = [
      'django.contrib.auth.hashers.Argon2PasswordHasher',
      'django.contrib.auth.hashers.PBKDF2PasswordHasher',
      'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher',
      'django.contrib.auth.hashers.BCryptSHA256PasswordHasher',
      'django.contrib.auth.hashers.BCryptPasswordHasher',
  ]
  
  # PASSWORD VALIDATION
  # https://docs.djangoproject.com/en/dev/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',
      },
  ]
  
  # AUTHENTICATION CONFIGURATION
  # ------------------------------------------------------------------------------
  AUTHENTICATION_BACKENDS = [
      'django.contrib.auth.backends.ModelBackend',
      'allauth.account.auth_backends.AuthenticationBackend',
  ]
  
  # Some really nice defaults
  ACCOUNT_AUTHENTICATION_METHOD = 'username'
  # NOTE: email verification disabled
  ACCOUNT_EMAIL_REQUIRED = False # True
  ACCOUNT_EMAIL_VERIFICATION = 'none' # 'mandatory'
  
  ACCOUNT_ALLOW_REGISTRATION = env.bool('DJANGO_ACCOUNT_ALLOW_REGISTRATION', True)
  ACCOUNT_ADAPTER = 'task_board.users.adapters.AccountAdapter'
  SOCIALACCOUNT_ADAPTER = 'task_board.users.adapters.SocialAccountAdapter'
  
  # Custom user app defaults
  # Select the correct user model
  AUTH_USER_MODEL = 'users.User'
  LOGIN_REDIRECT_URL = 'users:redirect'
  LOGIN_URL = 'account_login'
  
  # SLUGLIFIER
  AUTOSLUG_SLUGIFY_FUNCTION = 'slugify.slugify'
  
  
  # Location of root django.contrib.admin URL, use {% url 'admin:index' %}
  ADMIN_URL = r'^admin/'
  
  # LOGGING CONFIGURATION
  # ------------------------------------------------------------------------------
  # See: https://docs.djangoproject.com/en/dev/ref/settings/#logging
  # A sample logging configuration. The only tangible logging
  # performed by this configuration is to send an email to
  # the site admins on every HTTP 500 error when DEBUG=False.
  # See https://docs.djangoproject.com/en/dev/topics/logging for
  # more details on how to customize your logging configuration.
  LOGGING = {
      'version': 1,
      'disable_existing_loggers': False,
      'filters': {
          'require_debug_false': {
              '()': 'django.utils.log.RequireDebugFalse'
          }
      },
      'formatters': {
          'verbose': {
              'format': '%(levelname)s %(asctime)s %(module)s '
                        '%(process)d %(thread)d %(message)s'
          },
      },
      'handlers': {
          'mail_admins': {
              'level': 'ERROR',
              'filters': ['require_debug_false', ],
              'class': 'django.utils.log.AdminEmailHandler'
          },
          'console': {
              'level': 'DEBUG',
              'class': 'logging.StreamHandler',
              'formatter': 'verbose',
          },
      },
      'loggers': {
          'django.request': {
              'handlers': ['console'],
              'level': 'ERROR',
              'propagate': True
          },
          'django.security.DisallowedHost': {
              'level': 'ERROR',
              'handlers': ['console', ],
              'propagate': True
          },
          'general': {
              'level': 'DEBUG',
              'handlers': ['console', ],
              'propagate': True
          }
      }
  }
  