"""
Django settings for MES project.
Generated by 'django-admin startproject' using Django 2.0.3.
For more information on this file, see
https://docs.djangoproject.com/en/2.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.0/ref/settings/
"""

import os
#from myuser.models import MyUser

os.environ['DJANGO_SETTINGS_MODULE'] = 'MES.settings'
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
# approot = os.path.dirname(os.path.abspath(sys.argv[0]))
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
#BASE_DIR上级目录
PROJECT_DIR = os.path.dirname(BASE_DIR)

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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 's_yg26lmzp9qr%mxzp8ldu=s4zw(srzowhj7i_*yieegfyno=!'

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

    'p_admin',
    'p_mes',
    'p_sfm',
    'p_pdm',
    'p_opm',
    'p_aps',
    'p_scm',
    'p_wms',
    'p_ems',
    'p_crm',
    'p_erp',
    'p_cim',
    'p_cms',
    'p_wkf',

    'guardian', 

    'wagtail.contrib.forms',
    'wagtail.contrib.redirects',
    'wagtail.embeds',
    'wagtail.sites',
    'wagtail.users',
    'wagtail.snippets',
    'wagtail.documents',
    'wagtail.images',
    'wagtail.search',
    'wagtail.admin',
    'wagtail.core',

    'modelcluster',
    'taggit',
    
]

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',
    'wagtail.core.middleware.SiteMiddleware',
    'wagtail.contrib.redirects.middleware.RedirectMiddleware',
]


AUTHENTICATION_BACKENDS = [
    'django.contrib.auth.backends.ModelBackend', # this is default
    'guardian.backends.ObjectPermissionBackend',
]

ANONYMOUS_USER_NAME='95324'

ROOT_URLCONF = 'MES.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR+"/templates",),
                 os.path.join(BASE_DIR+"/templates/pages",),
                 os.path.join(BASE_DIR+"/templates/tpsfm",),
                 os.path.join(BASE_DIR+"/templates/tppdm",),
                 os.path.join(BASE_DIR+"/templates/tpopm",),
                 os.path.join(BASE_DIR+"/templates/tpaps",),
                 os.path.join(BASE_DIR+"/templates/tpscm",),
                 os.path.join(BASE_DIR+"/templates/tpwms",),
                 os.path.join(BASE_DIR+"/templates/tpems",),
                 os.path.join(BASE_DIR+"/templates/tpcrm",),
                 os.path.join(BASE_DIR+"/templates/tperp",),
                 os.path.join(BASE_DIR+"/templates/tpcim",),
                 os.path.join(BASE_DIR+"/templates/tpcms",),
                ],
        '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 = 'MES.wsgi.application'

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

DATABASES = {
    'default': {
	   'ENGINE':'sql_server.pyodbc',
	   'NAME':'MESHYC',
	   'HOST':'192.168.1.4',
       'PORT':'',
	   'USER': 'dbo_MES',
	   'PASSWORD': 'mes2017',
	   'OPTIONS':{
		    'DRIVER':'SQL Native Client',
            'dsn': 'mes',
            'MARS_Connection':True,
		},
    },

    'sqlite3': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'HYCMES.db'),
    },

    'default-local': {
	   'ENGINE':'sql_server.pyodbc',
	   'NAME':'MES02',
	   'HOST':'127.0.0.1',
       'PORT':'',
	   'USER': 'sa',
	   'PASSWORD': 'hyc2018',
	   'OPTIONS':{
		    'DRIVER':'SQL Native Client',
            'dsn': 'XiaolongX1',
            'MARS_Connection':True,
		},
    },

}

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


EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'  
# 每个邮箱都有不同的服务器 163邮箱为smtp.163.com，qq邮箱为smtp.qq.com 
EMAIL_HOST = 'smtp.hyc-system.com' #'smtp.hyc-system.com' 
EMAIL_PORT = 465
# 发送源即发送邮件的邮箱
EMAIL_HOST_USER ='gc17@hyc-system.com'    # 'gc17@foxmail.com' 
# 在邮箱中设置的客户端授权密码  
# 如果是aliyun邮箱这个是你账号的密码，如果是163/126邮箱或qq邮箱这个是授权码，
# 163/126的授权码会在你开通SMTP服务时自行设置，qq邮箱会分配一个授权码。
EMAIL_HOST_PASSWORD = 'HYChyc111' 
# qq邮箱此值为True，aliyun此值为False，163可以忽略此值
EMAIL_USE_SSL = True
#这个邮箱必须和上面的发送源邮箱相同。
EMAIL_FROM = 'HYC|MES<gc17@hyc-system.com>'
# Internationalization
# https://docs.djangoproject.com/en/2.0/topics/i18n/

LANGUAGE_CODE = 'zh-hans'

TIME_ZONE = 'Asia/Shanghai'

USE_I18N = True

USE_L10N = True

USE_TZ = True

LOGIN_URL='/login/'

WAGTAIL_SITE_NAME = "CMS"
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.0/howto/static-files/

STATICFILES_FINDERS = [
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
]

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR,"static")
STATICFILES_DIRS = (
    ("css", os.path.join(STATIC_ROOT,'css')),
    ("js", os.path.join(STATIC_ROOT,'js')),
    ("img", os.path.join(STATIC_ROOT,'img')),
    ("fonts", os.path.join(STATIC_ROOT,'fonts')),
    ("admin", os.path.join(STATIC_ROOT,'admin')),
    )

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

