"""
Django settings for carrier_crawler project.

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

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

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

import os
import sys
import socket
import pymysql

pymysql.install_as_MySQLdb()
# 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.11/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'qya-6f5$n9ufh2y!um_u#11(uhso$bh!9@xx8)not1@+u-qy11'

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

ALLOWED_HOSTS = ['*']

# Application definition

INSTALLED_APPS = [
    'suit',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django_extensions',
    'applications.api',
    'applications.orms',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    '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 = 'conf.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 = 'conf.wsgi.application'

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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': "default_data",
        'USER': 'risk',
        'PASSWORD': 'riskpassword',
        'HOST': '127.0.0.1',
        'PORT': 3306
    },
    'crw': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'crawl_db',
        'USER': 'risk',
        'PASSWORD': 'riskpassword',
        'HOST': '127.0.0.1',
        'PORT': 3306
    },
    'cld': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'cleandata_db',
        'USER': 'risk',
        'PASSWORD': 'riskpassword',
        'HOST': '127.0.0.1',
        'PORT': 3306
    },

}

CACHES = {
    "yys": {
        "BACKEND": "django_redis.cache.RedisCache",
        "LOCATION": "redis://:redispassword@127.0.0.1:6379",
        "OPTIONS": {
            "CLIENT_CLASS": "django_redis.client.DefaultClient",
        }
    },
    "default": {
        "BACKEND": "django_redis.cache.RedisCache",
        "LOCATION": "redis://:redispassword@127.0.0.1:6379",
        "OPTIONS": {
            "CLIENT_CLASS": "django_redis.client.DefaultClient",
        }
    },
    "celery_broker": {
        "BACKEND": "django_redis.cache.RedisCache",
        "LOCATION": "redis://:redispassword@127.0.0.1:6379",
        "OPTIONS": {
            "CLIENT_CLASS": "django_redis.client.DefaultClient",
        }
    },
    "celery_backend": {
        "BACKEND": "django_redis.cache.RedisCache",
        "LOCATION": "redis://:redispassword@127.0.0.1:6379",
        "OPTIONS": {
            "CLIENT_CLASS": "django_redis.client.DefaultClient",
        }
    }
}

# Password validation
# https://docs.djangoproject.com/en/1.11/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',
    },
]

# logging
LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'simple': {
            'format': '%(asctime)s %(levelname)s %(module)s[%(lineno)d] %(message)s'
        },
        'json': {
            '()': 'pythonjsonlogger.jsonlogger.JsonFormatter',
            'format': ('%(asctime)s %(created)f %(exc_info)s %(filename)s %(funcName)s %(levelname)s %(levelno)s '
                       '%(lineno)d %(module)s %(message)s %(pathname)s %(process)s %(processName)s %(relativeCreated)d '
                       '%(thread)s %(threadName)s')
        },
    },
    'handlers': {
        'stdout_console': {
            'level': 'INFO',
            'class': 'logging.StreamHandler',
            'stream': sys.stdout,
            'formatter': 'simple',
        },

    },
    'loggers': {
        'django.request': {
            'handlers': ['stdout_console'],
            'propagate': True,
            'level': 'INFO',
        },
        'console_logger': {
            'level': 'INFO',
            'handlers': ['stdout_console'],
            'propagate': False
        },
        'celery.task': {
            'level': 'INFO',
            'handlers': ['stdout_console'],
            'propagate': False
        },
        'celery.worker': {
            'level': 'INFO',
            'handlers': ['stdout_console'],
            'propagate': False
        },
    }
}

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

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

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

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

STATIC_URL = '/static/'

# 数据库路由
DATABASE_ROUTERS = [
    "conf.db_router.DCRouter",
]
# email
EMAIL_HOST = ''
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
EMAIL_REVICER = []
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
RECEIVER_EMAIL_GROUP = []

ES_ADDR = '127.0.0.1'
ES_PORT = '9200'
ELK_USERNAME = ''
ELK_PWD = ''

# mongo数据库配置　
# Date format
DATE_FORMAT = SHORT_DATE_FORMAT = 'Y年n月j日'
DATE_INPUT_FORMATS = ('%Y-%m-%d',)
DATETIME_FORMAT = SHORT_DATETIME_FORMAT = 'Y年n月j日 H:i:s'
DATETIME_INPUT_FORMATS = ('%Y-%m-%d %H:%M:%S',)
TIME_FORMAT = 'H:i:s'
TIME_INPUT_FORMATS = ('%H:%M:%S',)
# Django suit
SUIT_CONFIG = {
    'ADMIN_NAME': '广告流量管理系统',
    'HEADER_DATE_FORMAT': DATE_FORMAT,
}

# 主机名
HOST_NAME = socket.gethostname()
