"""
Django settings for sh8email project.

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

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

# 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 = 'q&xot8*fg$b4dd9c1$+fqqj4!t4e%jk_3=un#!g9*!q%(_t@zd'

DEBUG = True

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

ALLOWED_HOSTS = []

# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.humanize',

    'sh8core',
    'web',
    'rest',
    'recvmail',
    'batch',
    'backdoor',

    'rest_framework',
    'django_slack',
)

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 = 'sh8email.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'sh8email/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 = 'sh8email.wsgi.application'

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

LANGUAGE_CODE = 'ko'

TIME_ZONE = 'Asia/Seoul'

USE_I18N = True

USE_L10N = True

USE_TZ = True

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

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

# html_sanitizer settings
SANITIZER_ALLOWED_TAGS = ['html', 'head', 'title', 'body', 'meta',
                          'a', 'img', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6',
                          'footer', 'header', 'hgroup', 'nav',
                          'dd', 'div', 'dl', 'dt', 'figcaption', 'figure',
                          'hr', 'li', 'main', 'ol', 'p', 'pre', 'ul',
                          'abbr', 'b', 'br', 'cite', 'code', 'em',
                          'i', 'mark', 'q', 's', 'small', 'span', 'strong',
                          'sub', 'sup', 'u', 'area', 'caption', 'col', 'colgroup',
                          'table', 'tbody', 'td', 'tfoot', 'th', 'thead', 'tr',
                          'button']
SANITIZER_ALLOWED_ATTRIBUTES = ['href', 'http-equiv', 'content', 'name', 'charset', 'yahoo', 'src', 'class', 'id', ]
SANITIZER_ALLOWED_STYLES = []

# Mail receiving server settings
MAIL_SERVER_PORT = 2525

# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'sh8email',
        'USER': 'sh8email',
        'PASSWORD': os.getenv('SH8EMAIL_POSTGRES_PW', 'password'),
        'HOST': 'localhost',
        'POST': '5432',
        'ATOMIC_REQUESTS': True,
    }
}

# Logging
# https://docs.djangoproject.com/en/1.8/topics/logging/
LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'with_time': {
            'format': '[%(levelname)s] [%(asctime)s] [Logger: %(name)s]\n%(message)s'
        },
    },
    'filters': {
        'require_debug_false': {
            '()': 'django.utils.log.RequireDebugFalse',
        },
        'require_debug_true': {
            '()': 'django.utils.log.RequireDebugTrue',
        },
    },
    'handlers': {
        'console': {
            'level': 'INFO',
            'class': 'logging.StreamHandler',
            'formatter': 'with_time'
        },
        'null': {
            'class': 'logging.NullHandler',
        },
        'slack_admins': {
            'level': 'ERROR',
            'filters': ['require_debug_false'],
            'class': 'django_slack.log.SlackExceptionHandler',
        },
    },
    'loggers': {
        'django': {
            'handlers': ['console', 'slack_admins'],
        },
        'django.request': {
            'handlers': ['console', 'slack_admins'],
            'level': 'ERROR',
            'propagate': False
        },
        'django.security': {
            'handlers': ['console', 'slack_admins'],
            'level': 'ERROR',
            'propagate': False,
        },
        'django.security.DisallowedHost': {
            'handlers': ['null'],
            'propagate': False,
        }
    },
    'root': {
        'handlers': ['console', 'slack_admins'],
        'level': 'INFO'
    }
}

# django-slack
# https://django-slack.readthedocs.io/
# This is required to just for a placeholder.
# Otherwise, "ValueError: token parameter is required if custom endpoint URL is not specified" is occurred.
SLACK_TOKEN = 'dev_slack_token_LOL'

# Backdoor
BACKDOOR_KEY = 'goback'
