"""
Django settings for shielddash project.

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

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

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

import os

import dj_database_url
from decouple import config


# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = config('SECRET_KEY', default='change me to a real secret key')

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = config('DEBUG', default=False, cast=bool)

ALLOWED_HOSTS = ['*']

DOMAIN = config('DOMAIN', default='localhost:8000')

STATIC_ROOT = config('STATIC_ROOT', default=os.path.join(BASE_DIR, 'static'))
STATIC_URL = config('STATIC_URL', '/static/')

INSTALLED_APPS = [
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.staticfiles',

    'django.contrib.admin',
    'django.contrib.sessions',
    'django.contrib.messages',

    'rest_framework',
    'googleauth',
    'shielddash.api',
]

MIDDLEWARE_CLASSES = [
    'django.middleware.security.SecurityMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'shielddash.middleware.CORSMiddleware'
]

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'APP_DIRS': True,
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        'OPTIONS': {
            'context_processors': [
                'django.contrib.auth.context_processors.auth',
                'django.template.context_processors.debug',
                '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',
                'social.apps.django_app.context_processors.backends',
                'social.apps.django_app.context_processors.login_redirect',
                'shielddash.api.context_processors.google_auth_key',
            ],
        }
    }
]

ROOT_URLCONF = 'shielddash.urls'

TEMPLATES = []

WSGI_APPLICATION = 'shielddash.wsgi.application'

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

DEFAULT_DATABASE = config(
    'DATABASE_URL',
    default='postgresql://shielddash:shielddash@localhost:5432/shielddash',
    cast=dj_database_url.parse)

DATABASES = {
    'default': DEFAULT_DATABASE,
}

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

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = False

USE_L10N = False

USE_TZ = False

AUTHENTICATION_BACKENDS = (
    'googleauth.backends.GoogleAuthBackend',
)

REST_FRAMEWORK = {
}

GOOGLEAUTH_CLIENT_ID = config('GOOGLEAUTH_CLIENT_ID', '676697640342-o9mhtndrj60dk7jksdmmunetfmuqng4q.apps.googleusercontent.com')
GOOGLEAUTH_CLIENT_SECRET = config('GOOGLEAUTH_CLIENT_SECRET', '_HoDDGIq_ZrhBiES-ozIhUgh')
GOOGLEAUTH_APPS_DOMAIN = 'mozilla.com'
GOOGLEAUTH_CALLBACK_DOMAIN = DOMAIN
GOOGLEAUTH_USE_HTTPS = (DOMAIN != 'localhost:8000')
LOGIN_REDIRECT_URL = '/retention?start=20160101&end=20160102'
