]>
Commit | Line | Data |
---|---|---|
e5424f29 MR |
1 | from flask import Flask |
2 | from flask_bootstrap import Bootstrap | |
3 | from config import ADMINS, MAIL_SERVER, MAIL_PORT, MAIL_USERNAME, MAIL_PASSWORD | |
4 | from flask_login import LoginManager | |
5 | from flask_wtf.csrf import CSRFProtect | |
6 | ||
7 | app = Flask(__name__) | |
8 | app.config.from_object('config') | |
9 | lm = LoginManager() | |
10 | lm.init_app(app) | |
11 | lm.login_view = 'login' | |
12 | bootstrap = Bootstrap(app) | |
13 | csrf = CSRFProtect() | |
14 | csrf.init_app(app) | |
15 | ||
16 | if not app.debug: | |
17 | import logging | |
18 | ||
19 | from logging.handlers import SMTPHandler, RotatingFileHandler | |
20 | credentials = None | |
21 | if MAIL_USERNAME or MAIL_PASSWORD: | |
22 | credentials = (MAIL_USERNAME, MAIL_PASSWORD) | |
23 | mail_handler = SMTPHandler((MAIL_SERVER, MAIL_PORT), 'no-reply@' + MAIL_SERVER, ADMINS, 'PWP failure', credentials) | |
24 | mail_handler.setLevel(logging.ERROR) | |
25 | mail_handler.setFormatter(logging.Formatter('%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]')) | |
26 | app.logger.addHandler(mail_handler) | |
27 | ||
28 | file_handler = RotatingFileHandler('log/pwp.log', 'a', 1 * 1024 * 1024, 10) | |
29 | file_handler.setFormatter(logging.Formatter('%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]')) | |
30 | app.logger.addHandler(file_handler) | |
31 | ||
32 | app.logger.setLevel(logging.INFO) | |
33 | file_handler.setLevel(logging.INFO) | |
34 | app.logger.info('pwp startup') | |
35 | ||
36 | from app import views, models | |
37 | lm.anonymous_user = models.MyAnonymous | |
38 |