#!/usr/bin/env python
# coding: utf-8

# config.py

import os
basedir = os.path.abspath(os.path.dirname(__file__))

class Config:
    SECRET_KEY = os.environ.get('SECRET_KEY') or 'xxxxxxxxxxxxxxxxxxxSECRET_KEYxxxxxxxxxxxxxxxxxxxxxxxx'
	
    SQLALCHEMY_COMMIT_ON_TEARDOWN = True
    SQLALCHEMY_TRACK_MODIFICATIONS = True
    ALLOWED_EXTENSIONS = ['png', 'jpeg', 'jpg', 'gif']
    UPLOAD_FOLDER = os.path.join(basedir, 'upload')
    MATERIAL_COUNT_PER_PAGE = 15
    ADMINISTER = 'admin@buglist.com'
    
    # 指定本地资源
    #USER_DEF_CDN_BOOTSTRAP = '/static/bootstrap-3.3.7/'
    #USER_DEF_CDN_JQUERY = '/static/jquery/1.12.4/'

    @staticmethod
    def init_app(app):
        pass
        
class DevelopmentConfig(Config):
    DEBUG = True
    
    SQLALCHEMY_DATABASE_URI = os.environ.get('DEV_DATABASE_URL') or 'sqlite:///' + os.path.join(basedir, 'data-dev.sqlite')
    
    @classmethod
    def init_app(cls, app):
        Config.init_app(app)
        
        import logging
        from logging.handlers import RotatingFileHandler
        # 日志，循环记录，最大日志文件4k，循环文件数量3
        handler = RotatingFileHandler(os.path.join(basedir, 'buglist.log'), maxBytes=4096, backupCount=3)
        
        # 日志格式
        formatter = logging.Formatter('%(name)s - %(asctime)s - %(levelname)s - %(message)s')
        handler.setFormatter(formatter)
        handler.setLevel(logging.INFO)
        
        app.logger.addHandler(handler)
        
        
class TestingConfig(Config):
    TESTING = True
    SQLALCHEMY_DATABASE_URI = os.environ.get('TEST_DATABASE_URL') or 'sqlite:///' + os.path.join(basedir, 'data-test.sqlite')

config = {
    'testing': TestingConfig,
    'default': DevelopmentConfig
}