"""
Django settings for IQ project.

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

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 = 'u_j-)y)0am#i+e3=!h_)9#na$8h0dgq6s(i0&7z627ygfb0)vg'

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

ALLOWED_HOSTS = ['*']


# Application definition

INSTALLED_APPS = [
    'QtCompetence.apps.QtCompetenceConfig',
    'QtCompetence.templatetags',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    #'guardian',
    'django_apscheduler',
    'django_filters',
    'widget_tweaks',
]

AUTHENTICATION_BACKENDS = (
    'QtCompetence.backends.QtCompetenceBackend', # 自定义鉴权admin
    'django.contrib.auth.backends.ModelBackend', # this is default
    #'guardian.backends.ObjectPermissionBackend',
)

#每页五条数据
REST_FRAMEWORK={  
    'DEFAULT_PAGINATION_CLASS':'rest_framework.pagination.PageNumberPagination',
    'PAGE_SIZE':5
}

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',
    #'casbin_middleware.middleware.CasbinMiddleware', # Add this line, must after AuthenticationMiddleware.
]

ROOT_URLCONF = 'IQ.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'QtCompetence/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',
                # 处理media文件页面显示
                'django.template.context_processors.media',
            ],
            'libraries':{
                "extra_tags":"QtCompetence.templatetags.extra_tags",
            }
        },
    },
]

WSGI_APPLICATION = 'IQ.wsgi.application'


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

DATABASES = {
    #product
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'IQ',
        'USER': 'root',
        'PASSWORD':'123456',
        'HOST':'127.0.0.1',
        'PORT':'3306'
    },
    #develop
    # 'default': {
    #     'ENGINE': 'django.db.backends.mysql',
    #     'NAME': 'IQ',
    #     'USER': 'remoteroot',
    #     'PASSWORD':'123456',
    #     'HOST':'10.192.104.156',
    #     'PORT':'3306'
    # },
    'hr': {
        'ENGINE': 'django.db.backends.oracle',
        'NAME': 'tjdb024-vip.auto.contiwan.com:1521/GTJ.auto.contiwan.com',
        'USER': 'QMSAdmin',
        'PASSWORD':'QMSAdmin1'
    }
}


# 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/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'Asia/Shanghai'

USE_I18N = True

USE_L10N = True

# 改为False, 存入数据库的时间才正常, 否则会比正常时间少八个小时
USE_TZ = False

#必须设为1否则admin无法正确显示
SITE_ID = 1

#时间格式自定义
USE_L10N = False
DATE_FORMAT = 'Y-m-d'
DATETIME_FORMAT = 'Y-m-d H:i:s'

#关闭浏览器清除session
SESSION_EXPIRE_AT_BROWSER_CLOSE=True

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

STATIC_URL = '/static/'

STATIC_ROOT = os.path.join(BASE_DIR, "static")

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'QtCompetence/static'),
)

MEDIA_URL = '/media/'   # 媒体文件别名(相对路径) 和 绝对路径
MEDIA_ROOT = os.path.join(BASE_DIR, 'QtCompetence/media')

ADMIN_LOGIN = 'admin'
ADMIN_PASSWORD = 'pbkdf2_sha256$30000$Vo0VlMnkR4Bk$qEvtdyZRWTcOsCnI/oQ7fVOu1XAURIZYoOZ3iq8Dr4M='

AUTH_USER_MODEL = 'QtCompetence.is_user'

# GUARDIAN_GET_INIT_ANONYMOUS_USER = 'QtCompetence.models.get_anonymous_user_instance'
# ANONYMOUS_USER_NAME = 'Anonymous'

#email
#EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.office365.com'
EMAIL_HOST_USER = 'uic57948@contiwan.com'
#EMAIL_HOST_USER = 'feng.an@continental-corporation.com'
EMAIL_PORT = 587
#EMAIL_FROM = 'uic57948@contiwan.com'
#EMAIL_HOST_PASSWORD = 'Contiaf920808'