Example #1
0
def init_mfr(app):
    """Register all available FileHandlers and collect each
    plugin's static assets to the app's static path.
    """
    # Available file handlers
    mfr.register_filehandlers(ALL_HANDLERS)

    # Update mfr config with static path and url
    mfr.config.update({
        # Base URL for static files
        'ASSETS_URL': os.path.join(app.static_url_path, 'mfr'),
        # Where to save static files
        'ASSETS_FOLDER': os.path.join(app.static_folder, 'mfr'),
    })
    mfr.collect_static(dest=mfr.config['ASSETS_FOLDER'])
Example #2
0
def init_mfr(app):
    """Register all available FileHandlers and collect each
    plugin's static assets to the app's static path.
    """
    # Available file handlers
    mfr.register_filehandlers(ALL_HANDLERS)

    # Update mfr config with static path and url
    mfr.config.update({
        # Base URL for static files
        'ASSETS_URL': os.path.join(app.static_url_path, 'public', 'mfr'),
        # Where to save static files
        'ASSETS_FOLDER': os.path.join(app.static_folder, 'public', 'mfr'),
    })
    mfr.collect_static(dest=mfr.config['ASSETS_FOLDER'])
def create_app(**kwargs):
    """Create and return a Flask app instance"""

    # create app; load config
    app = Flask(__name__)
    app.config.from_pyfile(os.path.join(HERE, 'app_config.py'))
    app.config.update(**kwargs)

    # Configure MFR
    mfr.config.from_pyfile(os.path.join(HERE, 'mfr_config.py'))
    # Local overrides
    mfr.config.from_pyfile(os.path.join(HERE, 'mfr_config_local.py'), silent=True)
    # update static url and folder
    mfr.config.update({
        # Base URL for static files
        'STATIC_URL': os.path.join(app.static_url_path, 'mfr'),
        # Where to save static files
        'STATIC_FOLDER': os.path.join(app.static_folder, 'mfr'),
    })
    app.logger.debug('Config: {0}'.format(mfr.config))
    app.logger.debug('Registered handlers: {0}'.format(mfr.config['HANDLERS']))
    mfr.collect_static()

    # Set up error handlers
    @app.errorhandler(404)
    def not_found_error(error):
        return render_template('404.html'), 404

    @app.errorhandler(500)
    def generic_server_error(error):
        return render_template('500.html'), 500

    @app.errorhandler(501)
    def not_implemented_error(error):
        return render_template('501.html'), 501

    # register blueprints

    from .main.views import mod as main_module
    app.register_blueprint(main_module)

    from .render.views import mod as render_module
    app.register_blueprint(render_module)

    return app