"""
Django settings for MyEducation project.

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

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

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

import os
import sys

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# Add apps folder to path
sys.path.insert(0, BASE_DIR)
sys.path.insert(0, os.path.join(BASE_DIR, 'apps'))
sys.path.insert(0, os.path.join(BASE_DIR, 'extra_apps'))

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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '-g$a=%oc3lz10=tn9%9@b^)%d3a&ji#0rw9t!$6pw7-k%s=0ia'

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

ALLOWED_HOSTS = [] # Debug mode = 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',
    # apps
    'user.apps.UserConfig',
    'course.apps.CourseConfig',
    'organization.apps.OrganizationConfig',
    'operation.apps.OperationConfig',
    'blog.apps.BlogConfig',
    # extra_apps
    'xadmin',
    'crispy_forms',
    'captcha',
    'pure_pagination',
    'DjangoUeditor',
]

# 用户自定义model
AUTH_USER_MODEL = 'user.UserProfile'

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

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, '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',
                # Customized
                'django.template.context_processors.media', # 在Django2中使用"media"文件夹
                'blog.views.global_settings',
            ],
        },
    },
]

WSGI_APPLICATION = 'MyEducation.wsgi.application'

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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'myeducation',
        'USER': 'root',
        'PASSWORD': 'jee911jee',
        'HOST': '127.0.0.1',
        'PORT': '3306',
        # 'OPTIONS': {'init_command': 'SET default_storage_engine=INNODB;'}, # 如果是MySQL 5.7 和以上版本
        'OPTIONS': {
            'init_command': "SET default_storage_engine=INNODB;"
                            "SET sql_mode='STRICT_TRANS_TABLES';"
                            "SET GLOBAL group_concat_max_len=102400;"
                            "SET charset utf8"
        }
    }
}

# Password validation
# https://docs.djangoproject.com/en/2.2/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/2.2/topics/i18n/

LANGUAGE_CODE = 'en-us' # 英文
# LANGUAGE_CODE = 'zh-Hant' # 繁体中文
# LANGUAGE_CODE = 'zh-hans' # 简体中文

# TIME_ZONE = 'UTC'
# TIME_ZONE = 'Asia/Shanghai'
TIME_ZONE = 'US/Pacific'

USE_I18N = True

USE_L10N = True

# USE_TZ = True # 使用UTC时间(default)
USE_TZ = False  # 使用本地时间

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

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

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

AUTHENTICATION_BACKENDS = ('user.views.CustomizedBackend',)

EMAIL_HOST="smtp.sina.cn"
EMAIL_PORT=25
EMAIL_HOST_USER=""
EMAIL_HOST_PASSWORD=""
EMAIL_USE_TLS=False
EMAIL_FROM=""

PAGINATION_SETTINGS = {
    'PAGE_RANGE_DISPLAYED': 10,
    # 显示当前页面的相邻的页面数
    'MARGIN_PAGES_DISPLAYED': 2,
    # 显示的第一页和最后一页相邻的页数
    'SHOW_FIRST_PAGE_WHEN_INVALID': True,
    # 无效页面时，显示第一页而不是404页面
}

# 网站的基本信息配置
SITE_URL = 'http://localhost:8000/'
SITE_NAME = 'Jake Tech Lab'
SITE_DESC = '专注Python开发，欢迎和大家交流'
WEIBO_SINA = 'http://weibo.sina.com/yopoing'
WEIBO_TENCENT = 'http://weibo.qq.com/yopoing'
PRO_RSS = 'http://ww2w.baidu.com'
PRO_EMAIL = 'yopoing@vip.qq.com'

# 自定义日志输出信息
LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'console':{
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
        },
    },
    'loggers': {
        'django.db.backends': {
            'handlers': ['console'],
            'propagate': True,
            'level': 'DEBUG'
        }
    }
}