forked from fangjh13/Ftown
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
111 lines (92 loc) · 3.19 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#! -*- coding: utf-8 -*-
import os
class Config(object):
SQLALCHEMY_TRACK_MODIFICATIONS = True
SECRET_KEY = os.environ.get('SECRET_KEY') or 'qRk5fpfYwY5K22ci/l3/Ig=='
MAIL_USERNAME = os.environ.get('MAIL_USERNAME')
MAIL_PASSWORD = os.environ.get('MAIL_PASSWORD')
MAX_CONTENT_LENGTH = 10 * 1024 * 1024
REDIS_URL = "redis://@localhost:6379/1"
@staticmethod
def init_app(app):
pass
class DevelopmentConfig(Config):
DEBUG = True
SQLALCHEMY_DATABASE_URI = \
'mysql+pymysql://{}:{}@localhost/ftown'.format(
os.getenv('FTOWNUSER'), os.getenv('FTOWNPASSWD'))
MAIL_SERVER = "smtp.163.com"
MAIL_PORT = 25
MAIL_USE_TLS = False
MAIL_USE_SSL = False
class TestingConfig(Config):
TESTING = True
DEBUG = True
SQLALCHEMY_DATABASE_URI = \
'mysql+pymysql://{}:{}@localhost/ftown_test'.format(
os.getenv('FTOWNUSER'), os.getenv('FTOWNPASSWD'))
WTF_CSRF_ENABLED = False
MAIL_SERVER = "smtp.163.com"
MAIL_PORT = 25
MAIL_USE_TLS = False
MAIL_USE_SSL = False
# MAIL_SUPPRESS_SEND = False
class ProductionConfig(Config):
# gmail
# MAIL_SERVER = "smtp.gmail.com"
SQLALCHEMY_DATABASE_URI = \
'mysql+pymysql://{}:{}@localhost/ftown'.format(
os.getenv('FTOWNUSER'), os.getenv('FTOWNPASSWD'))
# gmail
# MAIL_PORT = 587
# MAIL_USE_TLS = True
# MAIL_USE_SSL = False
# 国内用163
MAIL_SERVER = "smtp.163.com"
MAIL_PORT = 25
MAIL_USE_TLS = False
MAIL_USE_SSL = False
@classmethod
def init_app(cls, app):
Config.init_app(app)
# email error to the administrators
import logging
from logging.handlers import SMTPHandler
secure = None
credentials = None
if getattr(cls, 'MAIL_USERNAME', None):
credentials = (cls.MAIL_USERNAME, cls.MAIL_PASSWORD)
if getattr(cls, 'MAIL_USE_TLS', None):
secure = ()
mail_handler = SMTPHandler(
mailhost=(cls.MAIL_SERVER, cls.MAIL_PORT),
fromaddr="Blog Admin <{0}>".format(cls.MAIL_USERNAME),
toaddrs=['[email protected]'],
subject='[Blog] Application Error',
credentials=credentials,
secure=secure,
timeout=10)
mail_handler.setLevel(logging.ERROR)
app.logger.addHandler(mail_handler)
# TimeRotatingFileHandler
from logging.handlers import TimedRotatingFileHandler
time_rotating_handler = TimedRotatingFileHandler(
filename='log/time_rotating_warning.log',
when='D',
backupCount=7,
encoding='utf-8',
utc=True
)
time_rotating_handler.setLevel(logging.WARNING)
formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s')
time_rotating_handler.setFormatter(formatter)
app.logger.addHandler(time_rotating_handler)
# handler proxy server headers
from werkzeug.contrib.fixers import ProxyFix
app.wsgi_app = ProxyFix(app.wsgi_app)
config = {
'development': DevelopmentConfig,
'testing': TestingConfig,
'production': ProductionConfig,
'default': DevelopmentConfig
}