"""
Django settings for bos project.

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

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

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

import os
import djcelery
from celery import Celery, platforms
djcelery.setup_loader()
platforms.C_FORCE_ROOT = True


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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '7_z7=$)87jny&7zt@eopkqdx48o@9zg8^1g@ei$@9*2w5ow%i7'

# 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',
    'department',
    'productline',
    'employee',
    'product',
    'issue',
    'djcelery',
    'about',
]

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 = 'bos.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 = 'bos.wsgi.application'


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

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


# Password validation
# https://docs.djangoproject.com/en/2.1/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/2.1/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.1/howto/static-files/

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

#   app --> model ---> 改变认证模型
AUTH_USER_MODEL = 'employee.Employee'

#   登录url
LOGIN_URL = 'employees:login'

# session cookie 过期时间


#   List of modules to import when celery starts.
CELERY_IMPORTS = ('issue.tasks', )
#   celery 中间人
BROKER_URL = 'redis://119.29.28.202:6666/1'
#   可见性超时时间定义了等待职程在消息分派到其他职程之前确认收到任务的秒数。
BROKER_TRANSPORT_OPTIONS = {'visibility_timeout': 3600}
#   Redis 中存储任务的状态和返回值
CELERY_RESULT_BACKEND = 'redis://119.29.28.202:6666/2'

# CELERY_ANNOTATIONS = {'utils.tasks': {'rate_limit': '10/s'}}

CELERY_TIMEZONE = 'Asia/Shanghai'
CELERY_ACCEPT_CONTENT = ['pickle']
CELERY_TASK_SERIALIZER = 'pickle'
CELERY_RESULT_SERIALIZER = 'json'
CELERYD_MAX_TASKS_PER_CHILD = 10
# CELERYD_LOG_FILE = BASE_DIR + "/logs/celery/celery.log"
# CELERYBEAT_LOG_FILE = BASE_DIR + "/logs/celery/beat.log"


#   git 配置
GIT_USER = 'root'
GIT_PASSWORD = 'feeyo#1234Noki'
GIT_CLONE_BASEDIR = '/data/'


#   rsync 配置
RSYNCD_CONFIG = '/etc/rsyncd.conf'
RSYNC_SERVER = '192.168.201.30'
RSYNC_SECRETS = '/etc/rsync.secrets'
REMOTE_RSYNC_PASSWORD = '/etc/rsync.password'



























"""
    启动指令 python manage.py celery worker -l info报错
    
    TypeError: can only concatenate tuple (not "NoneType") to tuple
    
     
    
    解决办法：
    
    D:\Python36\Lib\site-packages\djcelery\management\commands\celery.py
    
    文件的14--16行代码注释掉
"""
