forked from PyColorado/boulderpython.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
61 lines (52 loc) · 1.66 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
import os
basedir = os.path.abspath(os.path.dirname(__file__))
class Config:
SECRET_KEY = os.environ.get('SECRET_KEY') or \
'be1e74ae-a040-48e9-84bf-42d5e96e6363-dd1b82a0-43ca-40ff-96c3-1535eecd0fc5'
SSL_DISABLE = True
MAIL_SERVER = 'smtp.sendgrid.com'
MAIL_PORT = 587
MAIL_USE_TLS = True
MAIL_USERNAME = 'sendgrid_username'
MAIL_PASSWORD = 'sendgrid_password'
MAIL_SUBJECT_PREFIX = '[site.com]'
MAIL_SENDER = '[email protected]'
SITE_ADMIN = os.environ.get('SITE_ADMIN') or '[email protected]'
CACHE_TYPE = 'gaememcached'
GOOGLE_ANALYTICS_ID = 'UA-123456-78'
@staticmethod
def init_app(app):
pass
class AppConfig(Config):
"""
production config
"""
@classmethod
def init_app(cls, app):
"""
config
"""
Config.init_app(app)
# email errors to the administrators
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_TLS', None):
secure = ()
mail_handler = SMTPHandler(
mailhost=(cls.MAIL_SERVER, cls.MAIL_PORT),
fromaddr=cls.MAIL_SENDER,
toaddrs=[cls.SITE_ADMIN],
subject=cls.MAIL_SUBJECT_PREFIX + ' Application Error',
credentials=credentials,
secure=secure)
mail_handler.setLevel(logging.ERROR)
app.logger.addHandler(mail_handler)
config = {
'production': AppConfig,
'testing': AppConfig,
'default': AppConfig
}