from flask import Flask from flask_bootstrap import Bootstrap from flask_sqlalchemy import SQLAlchemy from config import ADMINS, MAIL_SERVER, MAIL_PORT, MAIL_USERNAME, MAIL_PASSWORD from flask_login import LoginManager app = Flask(__name__) app.config.from_object('config') lm = LoginManager() lm.init_app(app) lm.login_view = 'login' db = SQLAlchemy(app) bootstrap = Bootstrap(app) if not app.debug: import logging from logging.handlers import SMTPHandler, RotatingFileHandler credentials = None if MAIL_USERNAME or MAIL_PASSWORD: credentials = (MAIL_USERNAME, MAIL_PASSWORD) mail_handler = SMTPHandler((MAIL_SERVER, MAIL_PORT), 'no-reply@' + MAIL_SERVER, ADMINS, 'WPP failure', credentials) mail_handler.setLevel(logging.ERROR) mail_handler.setFormatter(logging.Formatter('%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]')) app.logger.addHandler(mail_handler) file_handler = RotatingFileHandler('log/wpp.log', 'a', 1 * 1024 * 1024, 10) file_handler.setFormatter(logging.Formatter('%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]')) app.logger.addHandler(file_handler) app.logger.setLevel(logging.INFO) file_handler.setLevel(logging.INFO) app.logger.info('wpp startup') from app import views, models