| import logging |
| from logging.handlers import SMTPHandler, RotatingFileHandler |
| import os |
| |
| from flask import Flask, request, current_app |
| from flask_bootstrap import Bootstrap |
| from flask_login import LoginManager |
| from flask_mail import Mail |
| from flask_migrate import Migrate |
| from flask_misaka import Misaka |
| from flask_sqlalchemy import SQLAlchemy |
| |
| from config import Config |
| |
| db = SQLAlchemy() |
| migrate = Migrate() |
| login = LoginManager() |
| login.login_view = 'user.login' |
| mail = Mail() |
| bootstrap = Bootstrap() |
| markdown = Misaka() |
| |
| def create_app(config_class=Config): |
| app = Flask(__name__) |
| app.config.from_object(config_class) |
| |
| login.login_message_category = "danger" |
| db.init_app(app) |
| migrate.init_app(app, db) |
| login.init_app(app) |
| mail.init_app(app) |
| bootstrap.init_app(app) |
| markdown.init_app(app) |
| |
| from app.api import bp as api_bp |
| app.register_blueprint(api_bp, url_prefix='/api') |
| |
| from app.user import bp as user_bp |
| app.register_blueprint(user_bp) |
| |
| from app.booking import bp as booking_bp |
| app.register_blueprint(booking_bp) |
| |
| from app.errors import bp as errors_bp |
| app.register_blueprint(errors_bp) |
| |
| from app.main import bp as main_bp |
| app.register_blueprint(main_bp) |
| |
| if not app.debug and not app.testing: |
| auth = None |
| secure = None |
| |
| app.faq_content = load_content(app.config['CONTENT_DIR'], 'faq.md') |
| app.thelabs_content = load_content(app.config['CONTENT_DIR'], 'thelabs.md') |
| app.software_content = load_content(app.config['CONTENT_DIR'], 'software.md') |
| app.statistics_content = load_content(app.config['CONTENT_DIR'], 'statistics.md') |
| app.news_content = load_content(app.config['CONTENT_DIR'], 'news.md') |
| app.blog_content = load_content(app.config['CONTENT_DIR'], 'blog.md') |
| |
| mail_handler = SMTPHandler(mailhost='localhost', |
| fromaddr='nolabs-admin@nordix.org', |
| toaddrs=app.config['NOLABS_ADMINS'], |
| subject='Nolabs Failure', |
| credentials=auth, |
| secure=secure) |
| mail_handler.setLevel(logging.ERROR) |
| app.logger.addHandler(mail_handler) |
| |
| logs_dir = app.config['LOGS_DIR'] |
| file_handler = logs_dir + '/nolabs.log' |
| file_handler = RotatingFileHandler(file_handler, maxBytes=10240, |
| backupCount=10) |
| file_handler.setFormatter(logging.Formatter( |
| '%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]')) |
| file_handler.setLevel(logging.INFO) |
| app.logger.addHandler(file_handler) |
| |
| app.logger.setLevel(logging.INFO) |
| app.logger.info('Nolabs startup') |
| |
| return app |
| |
| def load_content(content_dir, filename): |
| file_path = content_dir + '/' + filename |
| file_content = "" |
| with open(file_path, 'r') as file: |
| file_content = file.read() |
| return file_content |
| |
| from app import models |