"""
Django settings for croquet project.

Generated by 'django-admin startproject' using Django 1.10.7.

For more information on this file, see
https://docs.djangoproject.com/en/1.10/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.10/ref/settings/
"""

from __future__ import absolute_import, unicode_literals

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os

from dotenv import load_dotenv
import django_ses
secrets_file = os.getenv('SECRETS_FILE', None)
if secrets_file:
    load_dotenv(secrets_file)


PROJECT_ROOT = os.path.join(os.path.dirname(__file__), '..', '..')
BASE_DIR = PROJECT_ROOT

# Application definition

INSTALLED_APPS = [
    'home',

    'wagtail.wagtailforms',
    'wagtail.wagtailredirects',
    'wagtail.wagtailembeds',
    'wagtail.wagtailsites',
    'wagtail.wagtailusers',
    'wagtail.wagtailsnippets',
    'wagtail.wagtaildocs',
    'wagtail.wagtailimages',
    'wagtail.wagtailsearch',
    'wagtail.wagtailadmin',
    'wagtail.wagtailcore',
    'wagtail.contrib.wagtailsearchpromotions',

    'compressor',
    'modelcluster',
    'rest_framework',
    'taggit',

    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

MIDDLEWARE = [
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.security.SecurityMiddleware',

    'wagtail.wagtailcore.middleware.SiteMiddleware',
    'wagtail.wagtailredirects.middleware.RedirectMiddleware',
]

ROOT_URLCONF = 'croquet.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
            os.path.join(PROJECT_ROOT, 'templates'),
        ],
        '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 = 'croquet.wsgi.application'

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'console': {
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
        },
     },
    'root': {
        'level': 'INFO',
        'handlers': ['console']
    },
}

# Database
# https://docs.djangoproject.com/en/1.10/ref/settings/#databases

DATABASES = {
    'default': {},
    'devel': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    },
    'prod': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'prod',
        'USER': os.getenv('PROD_DB_USER', ''),
        'PASSWORD': os.getenv('PROD_DB_PW', ''),
        'HOST': os.getenv('PROD_DB_HOST', ''),
        'PORT': '5432'
    }
}


# Internationalization
# https://docs.djangoproject.com/en/1.10/topics/i18n/

LANGUAGE_CODE = 'en-gb'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.10/howto/static-files/

STATICFILES_FINDERS = [
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    'compressor.finders.CompressorFinder',
]



STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static')
STATIC_URL = '/static/'

MEDIA_ROOT = os.path.join(PROJECT_ROOT, 'media')
MEDIA_URL = '/media/'


# Wagtail settings

WAGTAIL_SITE_NAME = "croquet"

# Base URL to use when referring to full URLs within the Wagtail admin backend
# - e.g. in notification emails. Don't include '/admin' or a trailing slash
BASE_URL = 'https://histoncroquet.org'

GOOGLE_MAPS_KEY = os.getenv('GOOGLE_MAPS_KEY', '')

WAGTAILADMIN_NOTIFICATION_FROM_EMAIL = os.getenv('SITE_FROM_EMAIL', '')

EMAIL_BACKEND = django_ses.SESBackend
AWS_ACCESS_KEY_ID = os.getenv('AWS_ACCESS_KEY_ID', '')
AWS_SECRET_ACCESS_KEY = os.getenv('AWS_SECRET_ACCESS_KEY', '')
AWS_SES_REGION_NAME = os.getenv('AWS_SES_REGION_NAME', '')
AWS_SES_REGION_ENDPOINT = os.getenv('AWS_SES_REGION_ENDPOINT', '')

@@ -480,25 +480,8 @@
 env%0A
-import django_ses
 %0Asec
@@ -4275,16 +4275,70 @@
 ', '')%0A%0A
+DEFAULT_FROM_EMAIL = os.getenv('SITE_FROM_EMAIL', '')%0A
 WAGTAILA
@@ -4364,39 +4364,31 @@
 ROM_EMAIL = 
-os.getenv('SITE
+DEFAULT
 _FROM_EMAIL'
@@ -4386,22 +4386,16 @@
 OM_EMAIL
-', '')
 %0A%0AEMAIL_
@@ -4404,16 +4404,17 @@
 CKEND = 
+'
 django_s
@@ -4426,16 +4426,17 @@
 SBackend
+'
 %0AAWS_ACC

correct email config