"""
Django settings for Django_Kaldi project.

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

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

# get the root directory of this project
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)

# this means ../../
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# this means .../../../
FILE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

# URL
GOP_ROOT = '/home/ubuntu/kaldi/egs/gop-compute'

# 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 = '+wtj1+!y))xbr0chto!408&3)q#9v=3r=waown&*eiu!o@ccq9'

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

ALLOWED_HOSTS = ['*']


# Application definition

INSTALLED_APPS = [
    # 'simpleui', 
    'django_crontab',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'Kaldi_speech',
    # 启用定时任务模块
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    # 禁用Django的 csrf检查
    #'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

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

WSGI_APPLICATION = 'Django_Kaldi.wsgi.application'


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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        # set the database file path
        'NAME': os.path.join(FILE_DIR, 'db.sqlite3'),
    }
}


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

# Cache, Using redis
CACHES = {
    "default": {
        "BACKEND": "django_redis.cache.RedisCache",
        "LOCATION": "redis://127.0.0.1:6379",
        "OPTIONS": {
            "CLIENT_CLASS": "django_redis.client.DefaultClient",
            "CONNECTION_POOL_KWARGS": {"max_connections": 1000}
        }
    }
}

# Internationalization
# https://docs.djangoproject.com/en/2.2/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/2.2/howto/static-files/

STATIC_URL = '/static/'

# 需要指定为绝对路径

STATIC_ROOT = os.path.join(FILE_DIR,'static')

# 配置 MEDIA_ROOT 作为上传文件在服务器中的基本路径

MEDIA_ROOT = os.path.join(FILE_DIR,'media')

# 配置 MEDIA_URL 作为公用URL，指向上传文件的基本路径

MEDIA_URL = '/media/'

WX_URL = 'https://api.weixin.qq.com/sns/jscode2session'

ACCESS_TOKEN_URL = 'https://api.weixin.qq.com/cgi-bin/token'

SEND_URL = 'https://api.weixin.qq.com/cgi-bin/message/send'

MESSAGE_TEMPLATE_ID = 'PgnEXYQ78_7wPLYwpyLpct5slrba1hkwVQw7mF_KenM'

APP_SECRECT = 'b1ee7e749ce757a9831dd942ac7e5730'

APP_ID = 'wx28edbe6419ec7914'

# Default response

NOT_FOUND = '{"status":404,"msg":"object not found"}'

SESSION_INVALID = '{"status":401,"msg":"session outdate"}'

BAD_REQUEST_TYPE = '{"status":402,"msg":"bad request type"}'

# Crontab Settings

CRONJOBS = [
    # 每天9：30分执行人物
    # 参数格式：('f1 f2 f3 f4 f5','app名.xxx.函数名,'>>输出文件路径')
    ('* * * * *','Kaldi_speech.views.sendSubscribeMessage','>>/home/ubuntu/Desktop/RestKaldi/log/crontab.log')
]