"""
Django settings for django_mini project.

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

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 dj_database_url
import pymysql
from pydantic.datetime_parse import timedelta

pymysql.version_info = (1, 4, 13, "final", 0)
pymysql.install_as_MySQLdb()

ENVIRONMENT = os.getenv('ENVIRONMENT', 'development')

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

# 设置目录
# sys.path.insert(0, os.path.join(BASE_DIR, 'django_mini'))

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

ALLOWED_HOSTS = ['*']

# Application definition

INSTALLED_APPS = [
    'simpleui',  # simpleui
    'import_export',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'whitenoise.runserver_nostatic',
    'django.contrib.staticfiles',
    'corsheaders',
    'rest_framework',
    'sslserver',
    'snippets',
    'story',
    'scenic',
    'user_info',
    'comment'
]

MIDDLEWARE = [
    'corsheaders.middleware.CorsMiddleware',
    'django.middleware.security.SecurityMiddleware',
    'whitenoise.middleware.WhiteNoiseMiddleware',
    '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',
]

# 这个跨域的问题很严重
CORS_ALLOW_CREDENTIALS = True
CORS_ORIGIN_ALLOW_ALL = True

# Origin '*' in CORS_ORIGIN_WHITELIST is missing scheme 出现该错误则将其注释掉
# CORS_ORIGIN_WHITELIST = (
#   "*"
# )

CORS_ALLOW_METHODS = (
    'DELETE',
    'GET',
    'OPTIONS',
    'PATCH',
    'POST',
    'PUT',
    'VIEW',
)

CORS_ALLOW_HEADERS = (
    'XMLHttpRequest',
    'X_FILENAME',
    'accept-encoding',
    'authorization',
    'content-type',
    'dnt',
    'origin',
    'user-agent',
    'x-csrftoken',
    'x-requested-with',
    'Pragma',
)

ROOT_URLCONF = 'django_mini.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',
                'snippets.views.global_setting',  # 获取模版全局配置
            ],
        },
    },
]

WSGI_APPLICATION = 'django_mini.wsgi.application'

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

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

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/1.11/howto/static-files/

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

# Django REST Framework
REST_FRAMEWORK = {
    'PAGE_SIZE': 4,
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework_simplejwt.authentication.JWTAuthentication',
    ),
    'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
    'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema',
}

SIMPLE_JWT = {
    'ACCESS_TOKEN_LIFETIME': timedelta(hours=5),
    'REFRESH_TOKEN_LIFETIME': timedelta(days=1),
}

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

WEB_ROOT = "http://127.0.0.1:8000"

SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')  # 设置请求协议为https

# SECURE_SSL_REDIRECT = True

# 网站的基本信息配置优先读取数据库配置  如果数据库没有数据 则读取此配置(数据库站点信息缓存2分钟)
SITE_NAME = 'T'  # 站点名称
SITE_YEAR = "2022"  # 站点年份
SITE_META_KEYWORDS = '代码的魅力,web前端,Python后端,小程序,安卓逆向,Python爬虫,渗透测试'  # 站点关键词
SITE_META_DESCRIPTION = "领略代码的魅力,分享web前端,html5,css3,Python后端代码分享,了解认知前沿技术"  # 站点描述
SITE_TITLE = 'Just For Fun'  # 博客标题
SITE_TYPE_CHINESE = '向着未来而生'  # 打字效果 中文内容
SITE_TYPE_ENGLISH = 'Being toward future'  # 打字效果 英文内容
SITE_HOME_TITLE = "CharmCode.cn"  # 站点标题
SITE_SOURCE = "tplan.cc"  # 站点来源
SITE_MAIL = '<EMAIL>'  # 我的邮箱
SITE_DOMAIN_URL = "https://www.tplan.cc"  # 域名地址
SITE_AVATAR = "https://image.3001.net/images/20200504/1588558613_5eaf7b159c8e9.jpeg"  # 关于页面头像
ABOUT_NAME = "T"  # about 页面名称
ABOUT_DESC = "about页面简介"  # about页面简介

SIMPLEUI_LOGIN_PARTICLES = False
SIMPLEUI_ANALYSIS = False
SIMPLEUI_STATIC_OFFLINE = True
SIMPLEUI_LOADING = False
SIMPLEUI_LOGO = 'https://image.3001.net/images/20200504/1588558613_5eaf7b159c8e9.jpeg'  # 默认后台后台想
SIMPLEUI_DEFAULT_THEME = 'admin.lte.css'
SIMPLEUI_HOME_INFO = True  # simple log

# MarkDown
X_FRAME_OPTIONS = 'SAMEORIGIN'



"""
Django settings for django_mini project.

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

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 dj_database_url
import pymysql
from pydantic.datetime_parse import timedelta

pymysql.version_info = (1, 4, 13, "final", 0)
pymysql.install_as_MySQLdb()

ENVIRONMENT = os.getenv('ENVIRONMENT', 'development')

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

# 设置目录
# sys.path.insert(0, os.path.join(BASE_DIR, 'django_mini'))

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

ALLOWED_HOSTS = ['*']

# Application definition

INSTALLED_APPS = [
    'simpleui',  # simpleui
    'import_export',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'whitenoise.runserver_nostatic',
    'django.contrib.staticfiles',
    'corsheaders',
    'rest_framework',
    'sslserver',
    'snippets',
    'story',
    'scenic',
    'user_info',
    'comment'
]

MIDDLEWARE = [
    'corsheaders.middleware.CorsMiddleware',
    'django.middleware.security.SecurityMiddleware',
    'whitenoise.middleware.WhiteNoiseMiddleware',
    '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',
]

# 这个跨域的问题很严重
CORS_ALLOW_CREDENTIALS = True
CORS_ORIGIN_ALLOW_ALL = True

# Origin '*' in CORS_ORIGIN_WHITELIST is missing scheme 出现该错误则将其注释掉
# CORS_ORIGIN_WHITELIST = (
#   "*"
# )

CORS_ALLOW_METHODS = (
    'DELETE',
    'GET',
    'OPTIONS',
    'PATCH',
    'POST',
    'PUT',
    'VIEW',
)

CORS_ALLOW_HEADERS = (
    'XMLHttpRequest',
    'X_FILENAME',
    'accept-encoding',
    'authorization',
    'content-type',
    'dnt',
    'origin',
    'user-agent',
    'x-csrftoken',
    'x-requested-with',
    'Pragma',
)

ROOT_URLCONF = 'django_mini.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',
                'snippets.views.global_setting',  # 获取模版全局配置
            ],
        },
    },
]

WSGI_APPLICATION = 'django_mini.wsgi.application'

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

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

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/1.11/howto/static-files/

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

# Django REST Framework
REST_FRAMEWORK = {
    'PAGE_SIZE': 4,
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework_simplejwt.authentication.JWTAuthentication',
    ),
    'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
    'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema',
}

SIMPLE_JWT = {
    'ACCESS_TOKEN_LIFETIME': timedelta(hours=5),
    'REFRESH_TOKEN_LIFETIME': timedelta(days=1),
}

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

WEB_ROOT = "http://127.0.0.1:8000"

SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')  # 设置请求协议为https

# SECURE_SSL_REDIRECT = True

# 网站的基本信息配置优先读取数据库配置  如果数据库没有数据 则读取此配置(数据库站点信息缓存2分钟)
SITE_NAME = 'T'  # 站点名称
SITE_YEAR = "2022"  # 站点年份
SITE_META_KEYWORDS = '代码的魅力,web前端,Python后端,小程序,安卓逆向,Python爬虫,渗透测试'  # 站点关键词
SITE_META_DESCRIPTION = "领略代码的魅力,分享web前端,html5,css3,Python后端代码分享,了解认知前沿技术"  # 站点描述
SITE_TITLE = 'Just For Fun'  # 博客标题
SITE_TYPE_CHINESE = '向着未来而生'  # 打字效果 中文内容
SITE_TYPE_ENGLISH = 'Being toward future'  # 打字效果 英文内容
SITE_HOME_TITLE = "CharmCode.cn"  # 站点标题
SITE_SOURCE = "tplan.cc"  # 站点来源
SITE_MAIL = '<EMAIL>'  # 我的邮箱
SITE_DOMAIN_URL = "https://www.tplan.cc"  # 域名地址
SITE_AVATAR = "https://image.3001.net/images/20200504/1588558613_5eaf7b159c8e9.jpeg"  # 关于页面头像
ABOUT_NAME = "T"  # about 页面名称
ABOUT_DESC = "about页面简介"  # about页面简介

SIMPLEUI_LOGIN_PARTICLES = False
SIMPLEUI_ANALYSIS = False
SIMPLEUI_STATIC_OFFLINE = True
SIMPLEUI_LOADING = False
SIMPLEUI_LOGO = 'https://image.3001.net/images/20200504/1588558613_5eaf7b159c8e9.jpeg'  # 默认后台后台想
SIMPLEUI_DEFAULT_THEME = 'admin.lte.css'
SIMPLEUI_HOME_INFO = True  # simple log

# MarkDown
X_FRAME_OPTIONS = 'SAMEORIGIN'



Django settings for django_mini project.  Generated by 'django-admin startproject' using Django 1.11.7.  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/ # Build paths inside the project like this: os.path.join(BASE_DIR, ...) # 设置目录 # sys.path.insert(0, os.path.join(BASE_DIR, 'django_mini')) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/ # Application definition # simpleui # 这个跨域的问题很严重 # Origin '*' in CORS_ORIGIN_WHITELIST is missing scheme 出现该错误则将其注释掉 # CORS_ORIGIN_WHITELIST = ( #   "*" # ) # 获取模版全局配置 # Password validation # https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators # Internationalization # https://docs.djangoproject.com/en/1.11/topics/i18n/ # 获取数据库本地时间 # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/1.11/howto/static-files/ # STATIC_ROOT = os.path.join(BASE_DIR, '/static') # Django REST Framework # print(BASE_DIR) # 设置请求协议为https # SECURE_SSL_REDIRECT = True # 网站的基本信息配置优先读取数据库配置  如果数据库没有数据 则读取此配置(数据库站点信息缓存2分钟) # 站点名称 # 站点年份 # 站点关键词 # 站点描述 # 博客标题 # 打字效果 中文内容 # 打字效果 英文内容 # 站点标题 # 站点来源 # 我的邮箱 # 域名地址 # 关于页面头像 # about 页面名称 # about页面简介 # 默认后台后台想 # simple log # MarkDown