"""
Django settings for sushe project.

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

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

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

import os

# 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/3.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '!w_j9q38%&#0rf5v+t2h6%=x3vi(vqwjx2r6-x-2h)&(gw9lgm'

# 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',
    # 'haystack', # 检索
    # 'users',
    'users.apps.UsersConfig',
    'phonenumber_field',    # 电话相关
    # 'blog'
    'blog.apps.BlogConfig',  # 注册 blog 应用，因为在BlogConfig类中对blog应用做了配置，为了使admin汉化，需要再加上它
    'blog.templatetags',    # blog自定义标签
    'comments.apps.CommentsConfig',  # 注册 comments 应用
    'pure_pagination',  # 分页

]

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

WSGI_APPLICATION = 'sushe.wsgi.application'


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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'hnsm',
        'USER':'root',
        'PASSWORD':'syh315923418',
        'HOST': '127.0.0.1',
        'PORT': '3306',
        # 'OPTIONS': {'charset': 'utf8mb4'}, # 数据库保存表情
    }
}


DEFAULT_CHARSET = 'utf8'

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

AUTH_USER_MODEL = 'users.User'

LANGUAGE_CODE = 'zh-hans'

TIME_ZONE = 'Asia/Shanghai'

USE_I18N = True

USE_L10N = True

USE_TZ = True


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

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

# 用户直接在网址上输入登录，传递不了next值，就会直接返回首页
LOGOUT_REDIRECT_URL = '/'
LOGIN_REDIRECT_URL = '/'

# 开发时终端接收邮件设置
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

# 告诉django要使用哪些backends对用户进行验证
AUTHENTICATION_BACKENDS = (
    # django内置的通过用户名进行验证
    'django.contrib.auth.backends.ModelBackend',
    # 我们写的通过email进行验证
    'users.backends.EmailBackend',
)

# django-pure-pagination 分页设置
PAGINATION_SETTINGS = {
    'PAGE_RANGE_DISPLAYED': 4, # 分页条当前页前后应该显示的总页数（两边均匀分布，因此要设置为偶数），
    'MARGIN_PAGES_DISPLAYED': 2, # 分页条开头和结尾显示的页数
    'SHOW_FIRST_PAGE_WHEN_INVALID': True, # 当请求了不存在页，显示第一页
}

# # 搜索设置
# HAYSTACK_CONNECTIONS = {
#     'default': {
#         'ENGINE': 'blog.whoosh_cn_backend.WhooshEngine',
#         'PATH': os.path.join(BASE_DIR, 'whoosh_index'),
#     },
# }
# HAYSTACK_SEARCH_RESULTS_PER_PAGE = 5    # 指定对搜索结果分页，暂定为5
# HAYSTACK_SIGNAL_PROCESSOR = 'haystack.signals.RealtimeSignalProcessor'  # 指何时更新索引
# # HAYSTACK_CUSTOM_HIGHLIGHTER = 'blog.utils.Highlighter'

