"""
Django settings for textbin app.

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

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

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.8/ref/settings/
"""
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
import sys

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


sys.path.insert(0, os.path.dirname(BASE_DIR))

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/media-files/
STATIC_URL = os.environ.get('TEXTBIN_STATIC_URL', '/static/')

_PATH = os.path.abspath(os.path.dirname(__file__))
STATIC_ROOT = os.environ.get('TEXTBIN_STATIC_ROOT',
                             os.path.join(_PATH, 'files', 'static'))

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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get('TEXTBIN_SECRET_KEY',
                            'rz_e@sj*9-&va!qaz7$=+vq)ej8=mext*4uprhcpe#3q_xr=d#')

# SECURITY WARNING: don't run with debug turned on in production!

# Debug=False only if TEXTBIN_DEBUG defined as 'False'
DEBUG = os.environ.get('TEXTBIN_DEBUG', 'True').capitalize()
if DEBUG == 'False':
    DEBUG = False
else:
    DEBUG = True

if 'TEXTBIN_ALLOWED_HOSTS' in os.environ:
    ALLOWED_HOSTS = [os.environ.get('TEXTBIN_ALLOWED_HOSTS')]
else:
    ALLOWED_HOSTS = []


APPEND_SLASH = True

# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'textbin',
    'rest_framework',
    'bootstrap3',
    'snowpenguin.django.recaptcha2',
)

# CAPTCHA KEYS
if DEBUG:
    # With the default test keys, you will always get No CAPTCHA and all verification requests will pass.
    RECAPTCHA_PUBLIC_KEY = "6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI"
    RECAPTCHA_PRIVATE_KEY = "6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe"
else:
    # Try to get keys from environment
    RECAPTCHA_PUBLIC_KEY = os.environ.get('TEXTBIN_RECAPTCHA_PUBLIC_KEY',
                                          "6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI")
    RECAPTCHA_PRIVATE_KEY = os.environ.get('TEXTBIN_RECAPTCHA_PRIVATE_KEY',
                                           "6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe")

# link with static bs3 files
BOOTSTRAP3 = {
    'include_jquery': False,
    'jquery_url': STATIC_URL + 'textbin/js/jquery-1.12.0.min.js',
    'base_url': STATIC_URL + 'textbin/',
    'css_url': STATIC_URL + 'textbin/css/bootstrap.min.css',
    'theme_url': STATIC_URL + 'textbin/css/bootstrap-theme.min.css',
    'javascript_url': STATIC_URL + 'textbin/js/bootstrap.min.js',
}

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': [],
    # 'DEFAULT_PERMISSION_CLASSES': [],
    'DEFAULT_PERMISSION_CLASSES': (
                    # set API to be accessible to any user
                    'rest_framework.permissions.AllowAny',
                ),
    'PAGE_SIZE': 10,  # to turn on pagination
}

MIDDLEWARE_CLASSES = (
    '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',
)

ROOT_URLCONF = 'textbin.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        '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 = 'textbin.wsgi.application'


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

if 'TEXTBIN_DATABASE_ENGINE' in os.environ:
    DATABASES = {
        'default': {
            'ENGINE': os.environ['TEXTBIN_DATABASE_ENGINE'],
            'NAME': os.environ['TEXTBIN_DATABASE_NAME'],
            'USER': os.environ['TEXTBIN_DATABASE_USER'],
            'PASSWORD': os.environ['TEXTBIN_DATABASE_PASSWORD'],
            'HOST': os.environ['TEXTBIN_DATABASE_HOST'],
            'ATOMIC_REQUESTS': True,
        }
    }
else:
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.sqlite3',
            'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
        }
    }


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

LANGUAGE_CODE = 'ru'

TIME_ZONE = 'Europe/Moscow'

USE_I18N = True

USE_L10N = True

USE_TZ = True
