-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
86 lines (67 loc) · 2.2 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
import os
base_dir = os.path.abspath(os.path.dirname(__file__))
class Config:
# session and cookie
# SERVER_NAME = '127.0.0.1:5000'
SECRET_KEY = 'hard to guess string'
SESSION_KEY_PREFIX = 'session:'
# email
MAIL_SERVER = 'smtp.163.com'
MAIL_PORT = 465
MAIL_USE_SSL = True
MAIL_USERNAME = '[email protected]'
MAIL_PASSWORD = 'zaq1xsw2'
MAIL_SENDER = 'Firefly Admin <[email protected]>'
MAIL_SUBJECT_PREFIX = '[Firefly]'
MAIL_ADMIN = '[email protected]'
# database
SQLALCHEMY_TRACK_MODIFICATIONS = False
SQLALCHEMY_RECORD_QUERIES = True
# celery
CELERY_BROKER_URL = 'redis://localhost:6379/0'
CELERY_RESULT_BACKEND = 'redis://localhost:6379/0'
CELERY_ACCEPT_CONTENT = ['pickle', 'json']
# common settings
PER_PAGE_SIZE = 10
@staticmethod
def init_app(app):
pass
class DevConfig(Config):
DEBUG = True
SQLALCHEMY_DATABASE_URI = 'postgresql://fuyun:fuyun@localhost:5432/firefly'
SQLALCHEMY_ECHO = True
class TestConfig(Config):
TESTING = True
SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(base_dir, 'test.db')
WTF_CSRF_ENABLED = False
SQLALCHEMY_ECHO = True
class ProdConfig(Config):
SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL')
@classmethod
def init_app(cls, app):
Config.init_app(app)
# email errors to admin
import logging
from logging.handlers import SMTPHandler
credentials = None
secure = None
if getattr(cls, 'MAIL_USERNAME', None) is not None:
credentials = (cls.MAIL_USERNAME, cls.MAIL_PASSWORD)
if getattr(cls, 'MAIL_USE_SSL', None):
secure = ()
mail_handler = SMTPHandler(
mailhost=(cls.MAIL_SERVER, cls.MAIL_PORT),
fromaddr=cls.MAIL_SENDER,
toaddrs=[cls.MAIL_ADMIN],
subject=cls.MAIL_SUBJECT_PREFIX + ' Application Error',
credentials=credentials,
secure=secure
)
mail_handler.setLevel(logging.ERROR)
app.logger.addHandler(mail_handler)
config = {
'development': DevConfig,
'testing': TestConfig,
'production': ProdConfig,
'default': DevConfig
}