<reponame>fitahol/fitahol
# coding=utf-8
"""
Django settings for fitahol project.

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

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

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.9/ref/settings/
"""
import os
from pythonjsonlogger import jsonlogger

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

PROJECT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__),
                               os.pardir))

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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '<KEY>'

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

ALLOWED_HOSTS = ['*']

# 跨域配置
CORS_ORIGIN_WHITELIST = ("127.0.0.1:3000",
                         "127.0.0.1:2211",
                         "192.168.199.101:3000",
                         "192.168.198.191:3000",
                         "192.168.199.101:2016")

CORS_ORIGIN_REGEX_WHITELIST = ('^(http?://)?(\w+\.)?fitahol\.com$',
                               '^(http?://)?(\w+\.)?local\.com$')

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    'rest_framework',
    'rest_framework.authtoken',
    'kombu.transport.django',
    'djcelery',

    'account',
    'firmware',
    'gym',
    'schedule',
    'notifications',
    'fitness',
    'wechat'
]

MIDDLEWARE_CLASSES = [
    'django.middleware.security.SecurityMiddleware',
    'corsheaders.middleware.CorsMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

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


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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'fitahol',
        'USER': 'root',
        'PASSWORD': '<PASSWORD>',
        'HOST': '127.0.0.1',
        'PORT': '3306',
        'CHARSET': 'utf8',
        'OPTIONS': {
            'init_command': 'SET storage_engine=INNODB',
        },
    }
}

CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.db.DatabaseCache',
        'LOCATION': 'django_cache_dbs',
    }
}

# REST_FRAMEWORK settings
REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework.authentication.TokenAuthentication',
        # 'rest_framework.authentication.SessionAuthentication',
    ),
    'DEFAULT_RENDERER_CLASSES': (
        'rest_framework.renderers.JSONRenderer',
        'rest_framework.renderers.BrowsableAPIRenderer',
    ),
    'DEFAULT_PARSER_CLASSES': (
        'rest_framework.parsers.JSONParser',
        'rest_framework.parsers.FormParser',
        'rest_framework.parsers.MultiPartParser',
    ),
    'DEFAULT_PAGINATION_CLASS': 'utils.pagination.ResultsSetPagination',
    'PAGE_SIZE': 10,
    'MAX_PAGE_SIZE': 100,
    'DATETIME_FORMAT': '%Y-%m-%d %H:%M:%S',
    'DATE_FORMAT': '%Y-%m-%d',
    # 'DATE_INPUT_FORMAT': '%Y-%m-%d',
}

# Password validation
# https://docs.djangoproject.com/en/1.9/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/1.9/topics/i18n/

TIME_ZONE = 'Asia/Shanghai'

LANGUAGE_CODE = "zh-Hans"

USE_I18N = True

USE_L10N = True

USE_TZ = False

# 微信配置
WECHAT_TOKEN = "<PASSWORD>"

WECHAT_APP_ID = ""

WECHAT_APP_SECRET = ""

WECHAT_MEMBER_APP_ID = ""

WECHAT_MEMBER_APP_SECRET = ""

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

STATIC_URL = '/static/'

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

# Additional locations of static files
STATICFILES_DIRS = [
    os.path.join(PROJECT_ROOT, "static", "dist"),
]

MEDIA_URL = "/media/"

MEDIA_ROOT = os.path.join(PROJECT_ROOT, "media")

DOCS_URL = "/docs/"

DOCS_ROOT = os.path.join(PROJECT_ROOT, "docs", "_build", "html")

SERVER_URL = "http://www.fitahol.com"

HTTP_SERVER_URL = "https://api.fitahol.com"

# email server
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.163.com'
EMAIL_PORT = 25
EMAIL_HOST_USER = '<EMAIL>'
EMAIL_HOST_PASSWORD = ''
DEFAULT_FROM_EMAIL = '<EMAIL>'

# alidayu sms
ALIDAYU_APP_ID = ""
ALIDAYU_APP_SECRET = ""

LOGGING_PATH = os.path.join(PROJECT_ROOT, "logs")

try:
    from .server_conf import *  # noqa
except ImportError:
    pass

try:
    from .local_conf import *
except ImportError:
    pass

# celery settings
BROKER_URL = 'django://'

CELERY_TASK_RESULT_EXPIRES = 3600
CELERY_MAX_CACHED_RESULTS = 2000
CELERYD_MAX_TASKS_PER_CHILD = 100

CELERYBEAT_SCHEDULER = 'djcelery.schedulers.DatabaseScheduler'

CELERY_ACCEPT_CONTENT = ['json', 'pickle']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'

CELERY_ENABLE_UTC = False
CELERY_TIMEZONE = 'Asia/Shanghai'

import djcelery
djcelery.setup_loader()

# 日志依赖于settings 生效,放到最后面
LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'json': {
            '()': jsonlogger.JsonFormatter,
            'fmt': '%(levelname)s %(asctime)s %(process)d %(message)s',
            # 'format': '[%(asctime)s] %(levelname)s: %(message)s',
        },
        'verbose': {
            'format': '[%(asctime)s] %(levelname)s: %(message)s'
        },
        'error': {
            '()': jsonlogger.JsonFormatter,
            'fmt': '%(levelname)s %(asctime)s %(module)s %(process)d %(message)s %(pathname)s $(lineno)d $(funcName)s',
        },
    },
    'filters': {
    },
    'handlers': {
        'access_file_log': {
            'level': 'DEBUG',
            'class': 'logging.handlers.TimedRotatingFileHandler',
            'filename': os.path.join(LOGGING_PATH, "api_access.log"),
            'formatter': 'json',
            'when': 'midnight',
        },
        'error_file_log': {
            'level': 'INFO',
            'class': 'logging.handlers.TimedRotatingFileHandler',
            'filename': os.path.join(LOGGING_PATH, "api_error.log"),
            'formatter': 'verbose',
            'when': 'midnight',
        },
    },
    'loggers': {
        'default': {
            'handlers': ['access_file_log'],
            'level': 'DEBUG',
        },
        'error': {
            'handlers': ['error_file_log'],
            'level': 'ERROR',
        }
    }
}

# coding=utf-8
"""
Django settings for fitahol project.

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

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

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.9/ref/settings/
"""
import os
from pythonjsonlogger import jsonlogger

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

PROJECT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__),
                               os.pardir))

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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '<KEY>'

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

ALLOWED_HOSTS = ['*']

# 跨域配置
CORS_ORIGIN_WHITELIST = ("127.0.0.1:3000",
                         "127.0.0.1:2211",
                         "192.168.199.101:3000",
                         "192.168.198.191:3000",
                         "192.168.199.101:2016")

CORS_ORIGIN_REGEX_WHITELIST = ('^(http?://)?(\w+\.)?fitahol\.com$',
                               '^(http?://)?(\w+\.)?local\.com$')

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    'rest_framework',
    'rest_framework.authtoken',
    'kombu.transport.django',
    'djcelery',

    'account',
    'firmware',
    'gym',
    'schedule',
    'notifications',
    'fitness',
    'wechat'
]

MIDDLEWARE_CLASSES = [
    'django.middleware.security.SecurityMiddleware',
    'corsheaders.middleware.CorsMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

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


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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'fitahol',
        'USER': 'root',
        'PASSWORD': '<PASSWORD>',
        'HOST': '127.0.0.1',
        'PORT': '3306',
        'CHARSET': 'utf8',
        'OPTIONS': {
            'init_command': 'SET storage_engine=INNODB',
        },
    }
}

CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.db.DatabaseCache',
        'LOCATION': 'django_cache_dbs',
    }
}

# REST_FRAMEWORK settings
REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework.authentication.TokenAuthentication',
        # 'rest_framework.authentication.SessionAuthentication',
    ),
    'DEFAULT_RENDERER_CLASSES': (
        'rest_framework.renderers.JSONRenderer',
        'rest_framework.renderers.BrowsableAPIRenderer',
    ),
    'DEFAULT_PARSER_CLASSES': (
        'rest_framework.parsers.JSONParser',
        'rest_framework.parsers.FormParser',
        'rest_framework.parsers.MultiPartParser',
    ),
    'DEFAULT_PAGINATION_CLASS': 'utils.pagination.ResultsSetPagination',
    'PAGE_SIZE': 10,
    'MAX_PAGE_SIZE': 100,
    'DATETIME_FORMAT': '%Y-%m-%d %H:%M:%S',
    'DATE_FORMAT': '%Y-%m-%d',
    # 'DATE_INPUT_FORMAT': '%Y-%m-%d',
}

# Password validation
# https://docs.djangoproject.com/en/1.9/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/1.9/topics/i18n/

TIME_ZONE = 'Asia/Shanghai'

LANGUAGE_CODE = "zh-Hans"

USE_I18N = True

USE_L10N = True

USE_TZ = False

# 微信配置
WECHAT_TOKEN = "<PASSWORD>"

WECHAT_APP_ID = ""

WECHAT_APP_SECRET = ""

WECHAT_MEMBER_APP_ID = ""

WECHAT_MEMBER_APP_SECRET = ""

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

STATIC_URL = '/static/'

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

# Additional locations of static files
STATICFILES_DIRS = [
    os.path.join(PROJECT_ROOT, "static", "dist"),
]

MEDIA_URL = "/media/"

MEDIA_ROOT = os.path.join(PROJECT_ROOT, "media")

DOCS_URL = "/docs/"

DOCS_ROOT = os.path.join(PROJECT_ROOT, "docs", "_build", "html")

SERVER_URL = "http://www.fitahol.com"

HTTP_SERVER_URL = "https://api.fitahol.com"

# email server
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.163.com'
EMAIL_PORT = 25
EMAIL_HOST_USER = '<EMAIL>'
EMAIL_HOST_PASSWORD = ''
DEFAULT_FROM_EMAIL = '<EMAIL>'

# alidayu sms
ALIDAYU_APP_ID = ""
ALIDAYU_APP_SECRET = ""

LOGGING_PATH = os.path.join(PROJECT_ROOT, "logs")

try:
    from .server_conf import *  # noqa
except ImportError:
    pass

try:
    from .local_conf import *
except ImportError:
    pass

# celery settings
BROKER_URL = 'django://'

CELERY_TASK_RESULT_EXPIRES = 3600
CELERY_MAX_CACHED_RESULTS = 2000
CELERYD_MAX_TASKS_PER_CHILD = 100

CELERYBEAT_SCHEDULER = 'djcelery.schedulers.DatabaseScheduler'

CELERY_ACCEPT_CONTENT = ['json', 'pickle']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'

CELERY_ENABLE_UTC = False
CELERY_TIMEZONE = 'Asia/Shanghai'

import djcelery
djcelery.setup_loader()

# 日志依赖于settings 生效,放到最后面
LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'json': {
            '()': jsonlogger.JsonFormatter,
            'fmt': '%(levelname)s %(asctime)s %(process)d %(message)s',
            # 'format': '[%(asctime)s] %(levelname)s: %(message)s',
        },
        'verbose': {
            'format': '[%(asctime)s] %(levelname)s: %(message)s'
        },
        'error': {
            '()': jsonlogger.JsonFormatter,
            'fmt': '%(levelname)s %(asctime)s %(module)s %(process)d %(message)s %(pathname)s $(lineno)d $(funcName)s',
        },
    },
    'filters': {
    },
    'handlers': {
        'access_file_log': {
            'level': 'DEBUG',
            'class': 'logging.handlers.TimedRotatingFileHandler',
            'filename': os.path.join(LOGGING_PATH, "api_access.log"),
            'formatter': 'json',
            'when': 'midnight',
        },
        'error_file_log': {
            'level': 'INFO',
            'class': 'logging.handlers.TimedRotatingFileHandler',
            'filename': os.path.join(LOGGING_PATH, "api_error.log"),
            'formatter': 'verbose',
            'when': 'midnight',
        },
    },
    'loggers': {
        'default': {
            'handlers': ['access_file_log'],
            'level': 'DEBUG',
        },
        'error': {
            'handlers': ['error_file_log'],
            'level': 'ERROR',
        }
    }
}
# coding=utf-8 Django settings for fitahol project.  Generated by 'django-admin startproject' using Django 1.9.  For more information on this file, see https://docs.djangoproject.com/en/1.9/topics/settings/  For the full list of settings and their values, see https://docs.djangoproject.com/en/1.9/ref/settings/ # Build paths inside the project like this: os.path.join(BASE_DIR, ...) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! # SECURITY WARNING: don't run with debug turned on in production! # 跨域配置 # Database # https://docs.djangoproject.com/en/1.9/ref/settings/#databases # REST_FRAMEWORK settings # 'rest_framework.authentication.SessionAuthentication', # 'DATE_INPUT_FORMAT': '%Y-%m-%d', # Password validation # https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators # Internationalization # https://docs.djangoproject.com/en/1.9/topics/i18n/ # 微信配置 # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/1.9/howto/static-files/ # Additional locations of static files # email server # alidayu sms # noqa # celery settings # 日志依赖于settings 生效,放到最后面 # 'format': '[%(asctime)s] %(levelname)s: %(message)s',