-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
122 lines (91 loc) · 3.33 KB
/
config.py
File metadata and controls
122 lines (91 loc) · 3.33 KB
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
112
113
114
115
116
117
118
119
120
121
122
import os
BASE_DIR = os.path.abspath(os.path.dirname(__file__))
class Config:
JSON_AS_ASCII = False
SECRET_KEY = os.environ.get('SECRET_KEY', os.urandom(16))
SQLALCHEMY_COMMIT_ON_TEARDOWN = True
SQLALCHEMY_TRACK_MODIFICATIONS = True
# redis connect url
REDIS_URL = os.getenv('REDIS_URL')
# celery
CELERY_BROKER_URL = os.getenv('CELERY_BROKER_URL')
CELERY_RESULT_BACKEND = os.getenv('CELERY_RESULT_BACKEND')
# Mail_Config
MAIL_SUBJECT_PREFIX = '[HIDDEN-ISLAND]'
ADMIN_EMAIL = os.environ.get('ADMIN_EMAIL')
MAIL_SENDER = os.environ.get('MAIL_SENDER')
SENDGRID_API_KEY = os.environ.get('SENDGRID_API_KEY')
ARTICLES_SOURCE_DIR = os.path.join(BASE_DIR, 'articles')
ARTICLES_PER_PAGE = 7
COMMENTS_PER_PAGE = 7
MAX_ARTICLE_SIZE = 16 * 1024 * 1024
ALLOWED_FILE_EXTENSIONS = set(['md', 'markdown'])
@classmethod
def allowed_file(cls, filename):
return '.' in filename \
and filename.rsplit('.', 1)[1] in cls.ALLOWED_FILE_EXTENSIONS
@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(BASE_DIR, 'data-dev.sqlite')
class TestingConfig(Config):
TESTING = True
WTF_CSRF_ENABLED = False
SQLALCHEMY_DATABASE_URI = os.environ.get('TEST_DATABASE_URL') or \
'sqlite:///' + os.path.join(BASE_DIR, 'data-test.sqlite')
class ProductionConfig(Config):
SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL') or \
'sqlite:///' + os.path.join(BASE_DIR, 'data.sqlite')
@classmethod
def init_app(cls, app_):
super().init_app(app_)
# email errors to the administrators
import logging
from app.utils.log_handler import SendGridMailHandler
mail_handler = SendGridMailHandler(
recipient=cls.ADMIN_EMAIL,
subject=cls.MAIL_SUBJECT_PREFIX + 'Application error!'
)
mail_handler.setFormatter(logging.Formatter('''
Message type: %(levelname)s
Location: %(pathname)s:%(lineno)d
Module: %(module)s
Function: %(funcName)s
Time: %(asctime)s
Message:
%(message)s
'''))
mail_handler.setLevel(logging.ERROR)
app_.logger.addHandler(mail_handler)
class HerokuConfig(ProductionConfig):
@classmethod
def init_app(cls, app):
super().init_app(app)
# log to stderr
import logging
from logging import StreamHandler
file_handler = StreamHandler()
file_handler.setLevel(logging.INFO)
app.logger.addHandler(file_handler)
class DockerConfig(ProductionConfig):
"""use this when deploy by docker compose"""
@classmethod
def init_app(cls, app):
super().init_app(app)
# log to stderr
import logging
from logging import StreamHandler
file_handler = StreamHandler()
file_handler.setLevel(logging.INFO)
app.logger.addHandler(file_handler)
config = {
'development': DevelopmentConfig(),
'testing': TestingConfig(),
'production': ProductionConfig(),
'heroku': HerokuConfig(),
'docker': DockerConfig(),
'default': DevelopmentConfig(),
}