]> git.datanom.net - pwp.git/blame_incremental - app/__init__.py
initial commit
[pwp.git] / app / __init__.py
... / ...
CommitLineData
1from flask import Flask
2from flask_bootstrap import Bootstrap
3from config import ADMINS, MAIL_SERVER, MAIL_PORT, MAIL_USERNAME, MAIL_PASSWORD
4from flask_login import LoginManager
5from flask_wtf.csrf import CSRFProtect
6
7app = Flask(__name__)
8app.config.from_object('config')
9lm = LoginManager()
10lm.init_app(app)
11lm.login_view = 'login'
12bootstrap = Bootstrap(app)
13csrf = CSRFProtect()
14csrf.init_app(app)
15
16if 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
36from app import views, models
37lm.anonymous_user = models.MyAnonymous
38
This page took 0.026336 seconds and 5 git commands to generate.