# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from decouple import config, Csv
from corsheaders.defaults import default_headers
import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django_extensions',
    'tastypie',
    'core.apps.CoreConfig',
    'api.apps.ApiConfig',
    'corsheaders',
]
MIDDLEWARE = [
    'corsheaders.middleware.CorsMiddleware',
    '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',
]
ROOT_URLCONF = 'odoo_control.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 = 'odoo_control.wsgi.application'
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'app.db'),
    }
}
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',
    },
]
# AUTH_USER_MODEL = 'core.User'
LANGUAGE_CODE = 'es-PY'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
TASTYPIE_DEFAULT_FORMATS = ['json', 'xml']
SECRET_KEY = config('SECRET_KEY')
ALLOWED_HOSTS = config('ALLOWED_HOSTS', cast=Csv())
CORS_ORIGIN_ALLOW_ALL = config('DEBUG', default=False, cast=bool)
CORS_ALLOW_CREDENTIALS = True
DEBUG = config('DEBUG', default=False, cast=bool)
JWT_ACCEPT_HEADER = config('JWT_ACCEPT_HEADER')
JWT_PREFIX_HEADER = config('JWT_PREFIX_HEADER')
JWT_SECRET_KEY = config('JWT_SECRET_KEY')
SERVER_IP = config('SERVER_IP')
DOCKER_SOCK_DIR = config('DOCKER_SOCK_DIR')
DOCKER_NETWORK = config('DOCKER_NETWORK')
DOCKER_NETWORK_NAME = config('DOCKER_NETWORK_NAME', 'default')
ODOO_IMAGE = config('ODOO_IMAGE')
ODOO_ROOT_PATH = config('ODOO_ROOT_PATH')
ODOO_DEFAULT_FOLDERS = config('ODOO_DEFAULT_FOLDERS', cast=lambda x: dict([s.split(':') for s in x.split(',')]))
ODOO_PORTS_RANGE = config('ODOO_PORTS_RANGE', cast=Csv(int))
ODOO_CONF_FILENAME = config('ODOO_CONF_FILENAME', 'openerp-server')
ODOO_ADMIN_PASSWORD = config('ODOO_ADMIN_PASSWORD', 'admin')
ODOO_DB_CONTAINER = config('ODOO_DB_CONTAINER', 'postgres')
ODOO_DB_HOST = config('ODOO_DB_HOST', 'localhost')
ODOO_DB_PORT = config('ODOO_DB_PORT', default=5432, cast=int)
ODOO_DB_USER = config('ODOO_DB_USER', 'postgres')
ODOO_DB_PASSWORD = config('ODOO_DB_PASSWORD', 'root')
