"""
Django settings for Fresh project.

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

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

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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'n$3crs-@^#6k8a2swnv0vx@v7w+!l&^qi#4j7dl@$hcvq8&-=q'

# 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',
    'store',
    'user',
    'rest_framework',
    'ckeditor',
    'djcelery',
    'CeleryTask',
    'ckeditor_uploader',
]

MIDDLEWARE = [
    # 'django.middleware.cache.UpdateCacheMiddleware',
    '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',
    'Fresh.middleware.MiddlewareTest',
    # 'django.middleware.cache.FetchFromCacheMiddleware'
]

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

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

# 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 = False

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

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

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

CKEDITOR_UPLOAD_PATH = 'static/upload'
CKEDITOR_IMAGE_BACKEND = 'pillow'

APPID = "2016101000652497"

ALIPAY_PUBLIC_KEY_STRING = """-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAz6mmwgohEIq7gpO/acdRire4AXe6GeohT13mRLWIYK+Gf/ezxT+GjG1DM6UJX+JKn1eUacpKBCMe83GxcTFXIdr4Np136TDJ7OcAbprs4csmUa/vw2bxQXBK6PYrYwblUAxN0HlpJh7kPwM7IKut9e/XDMorGLqTgBOI/dLCvfIdNU1jZ+ozppIo93fEGqTjC/HUis5EziyEHmZbnLJGGgufdiVA2H+HVL68sDUd1VpSWqHAE+HrH3sVwP80wR2zgcz47XYUK5/0h0m7QcW4jbqNEvMJ+CRHS7Y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/TO2l+jTBhIj9pB8koBmxxiug65z+Mg9fj8lnQ/e4ZRQeGmZ2C/Kjy5dYEyBbNkZr0EkHgciMQhP0H3Ne5l+yGAjw/ENO3O479GxbpATH7S/sUah2uJPcCgYBfvSNx1/gWYaYQf6M+v/+RtS96Ph/i/C81JgvzS5pBOAbb1Q8PzhBdr7z7kVYOK8dpTSZD/h7BnAknDE3kR8O0b+R/WVmXkUWAL5ADJWI2xPGyP1ZEck20wX4+7GlxcV3OyCv4gBHGdsmPvafc07xFCA7YXxdNGDB+oO5ZkysdywKBgQDK/qGX5DBsFqlRJqHGwKDwzVhei8/hxujPTQRDQTPmQ+o0JW2LERd3+3vpQaSB37pQyAiYrYui2lAnS7VKQH+1T7ZuASp0/vsU9yQQSSDM/hSKFUmur8FxwOX7HaIJK0kv02Y00aAIb5Vc2BTQTpYgidq91Pt9rXcg/RpxlW8hYQKBgAEdfsZdixuI6eXP2nNKcuhSawphWeq8k2uwcdv+owLHD2LoQLW3RC6kJtxhzQNvnGpXUb6Sui/QJjp3vJieEoedUQ8Kc5dne6oDKaRIQHu5VbyIzvqrgncTvYg92PpYXT688ERCyppHaDFlAYKjTIHLhsxcynxhR4hba/UcHHyN
-----END REA PRIVATE KEY-----"""

REST_FRAMEWORK = {
    'DEFAULT_PERMISSION_CLASSES': [
        'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
    ],
    'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
    'PAGE_SIZE': 10,
    'DEFAULT_RENDERER_CLASSES': (
        'utils.rendererresponse.CustomRender',
    ),
    'DEFAULT_FILTER_BACKENDS': (
        'django_filters.rest_framework.DjangoFilterBackend',
    ),  # django-filter 自带的查询过滤器
}

# 发送邮件配置
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = False
# smpt服务地址
EMAIL_HOST = 'smtp.163.com'
EMAIL_PORT = 25
# 发送邮件的邮箱
# EMAIL_HOST_USER = 'xiaomin10041204@163.com'
EMAIL_HOST_USER = '13792936061@163.com'
# 在邮箱中设置的客户端授权密码
EMAIL_HOST_PASSWORD = 'python666'
# 收件人看到的发件人
EMAIL_FROM = '天天生鲜<13792936061@163.com>'
# EMAIL_FROM = '天天生鲜<xiaomin10041204@163.com>'

# celery配置
import djcelery

djcelery.setup_loader()  #
BROKER_URL = 'redis://127.0.0.1:6379/1'
CELERY_IMPORTS = ('CeleryTask.tasks',)  # 具体的任务文件
CELERY_TIMEZONE = TIME_ZONE  # 时区
CELERYBEAT_SCHEDULER = 'djcelery.schedulers.DatabaseScheduler'  # celery处理器

# celery的定时器
from celery.schedules import crontab
from celery.schedules import timedelta

CELERYBEAT_SCHEDULE = {
    # u'测试定时器': {
    #     "task": "CeleryTask.tasks.taskExample",
    #     "schedule": timedelta(seconds=30),
    #     "args": (),
    # },
    u'hello everybody': {
        "task": "CeleryTask.tasks.ding_talk",
        "schedule": timedelta(seconds=5),
        "args": (),
    }
}

# # MemcachedCache
# CACHES = {
#     'default': {
#         'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
#         'LOCATION': [
#             '127.0.0.1:11211'
#         ]
#     }
# }

# # 本地缓存
# CACHES = {
#     'default': {
#         'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
#     }
# }

# # redis的缓存
# CACHES = {
#     "default": {
#         "BACKEND": "django_redis.cache.RedisCache",
#         "LOCATION": "redis://127.0.0.1:6379/1",
#         "OPTIONS": {
#             "CLIENT_CLASS": "django_redis.client.DefaultClient",
#         }
#     }
# }

# 数据库缓存
CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.db.DatabaseCache',
        'LOCATION': 'cache_table'
    }
}

# CACHE_MIDDLEWARE_KEY_PREFIX = ''
# CACHE_MIDDLEWARE_SECONDS = 600
