# -*- coding: utf-8 -*-
"""
Django settings for djmessenger project.

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

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
# FYI: added for djmessenger
from django.utils.translation import ugettext_lazy as _

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = 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 = '1yr1sar0--#8qwl7$fi-86mk63)cofm5%$!d%!r!$f=sb+$e-)'

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

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'djmessenger',
    'testapp'
]

MIDDLEWARE_CLASSES = [
    'django.middleware.security.SecurityMiddleware',
    '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.locale.LocaleMiddleware',  # FYI: added for djmessenger
]

ROOT_URLCONF = 'testapp.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 = 'testapp.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.9/ref/settings/#databases
# FYI: added for djmessenger
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': "djmessenger",
        'USER': "",
        'PASSWORD': "",
        'HOST': 'localhost',
        'PORT': '5432',
        # 'ATOMIC_REQUESTS': True
    }
}


# Password validation
# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators

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',
    },
]


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

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'
# FYI: added for djmessenger
gettext = lambda s: s
LANGUAGES = (
    ('en', _('English')),
    ('zh-hant', _('Traditional Chinese')),
    ('zh', _('Traditional Chinese')),
    # ('zh-hans', _('Simplified Chinese')),
)
USE_I18N = True
LOCALE_PATHS = (
    os.path.join(BASE_DIR, '..', 'locale'),
)

USE_L10N = True

USE_TZ = True


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

STATIC_URL = '/static/'
# FYI: added for djmessenger
LOG_BASE_DIR = '/var/log/'
LOG_SUB_DIR = 'djm'
LOGGING = {
    'version': 1,
    'disable_existing_loggers': True,
    'filters': {
        'require_debug_false': {
            '()': 'django.utils.log.RequireDebugFalse'
        }
    },
    'formatters': {
        'simple': {
            'format': '[%(asctime)s] %(levelname)s %(message)s',
            'datefmt': '%Y-%m-%d %H:%M:%S'
        },
        'verbose': {
            'format': '[%(asctime)s] %(levelname)s [%(name)s.%(module)s.%(funcName)s:%(lineno)d] %(message)s',
            'datefmt': '%Y-%m-%d %H:%M:%S'
        },
    },
    'handlers': {
        'djmessenger': {
            'level': 'DEBUG',
            'class': 'logging.handlers.RotatingFileHandler',
            'filename': os.path.join(LOG_BASE_DIR, LOG_SUB_DIR, 'djmessenger.log'),
            'formatter': 'verbose',
            'maxBytes': 1024 * 1024 * 5,
            'backupCount': 5,
        },
        'console': {
            'class': 'logging.StreamHandler',
            'formatter': 'simple',
            'level': 'DEBUG'
        }
    },
    'loggers': {
        '': {
            'handlers': ['djmessenger', 'console'],
            'level': 'DEBUG',
            'propagate': True,
        },
        'djmessenger': {
            'handlers': ['djmessenger', 'console'],
            'level': 'DEBUG',
            'propagate': False,
        }
    },
}
# FYI: added for djmessenger
# djm settings
DJM_PAGE_ACCESS_TOKEN = 'EAABtMkLqTLoBAIQeQs3StkXAKXS5XG8vs1XsIl1ZBfhvaZC9UHSMlcK5dwD9bCpkE5wrHsR9mnp02WVD5yRNun7s8ErnafQZBED0KPaiclNFp75HjQtrZB8GItl9bEWjFnzaVA6Ka4FYUZCR8bXwT1XZC8FIoqrS4xRifT3HqXhwZDZD'
DJM_ENDPOINT = 'aef40e8e2b258e647fe84655eab910a7a70bc0031e382f01ba'
