view piecrust/admin/web.py @ 924:1bb704434ee2

formatting: Remove segment parts, you can use template tags instead. Segment parts were used to switch formatters insides a given content segment, but that's also achievable with template tags like `pcformat` in Jinja to some degree. It's not totally the same but removing it simplifies the code and improves performance.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 01 Oct 2017 20:36:04 -0700
parents ca357249a321
children 7ecb946bfafd
line wrap: on
line source

import os.path
import logging
from flask import Flask
from werkzeug import SharedDataMiddleware


logger = logging.getLogger(__name__)


def create_foodtruck_app(extra_settings=None):
    from .blueprint import foodtruck_bp

    app = Flask(__name__.split('.')[0], static_folder=None)
    app.config.from_object('piecrust.admin.settings')
    if extra_settings:
        app.config.update(extra_settings)

    root_dir = app.config.setdefault('FOODTRUCK_ROOT', os.getcwd())

    app.config.from_pyfile(os.path.join(root_dir, 'admin_app.cfg'),
                           silent=True)
    app.config.from_envvar('FOODTRUCK_SETTINGS', silent=True)

    # Add a special route for the `.well-known` directory.
    app.wsgi_app = SharedDataMiddleware(
        app.wsgi_app,
        {'/.well-known': os.path.join(root_dir, '.well-known')})

    # Setup logging/error handling.
    if app.config['DEBUG']:
        l = logging.getLogger()
        l.setLevel(logging.DEBUG)

    if not app.config['SECRET_KEY']:
        # If there's no secret key, create a temp one but mark the app as not
        # correctly installed so it shows the installation information page.
        app.config['SECRET_KEY'] = 'temp-key'

    # Register extensions and blueprints.
    bp_prefix = app.config['FOODTRUCK_URL_PREFIX']
    app.register_blueprint(foodtruck_bp, url_prefix=bp_prefix)

    logger.debug("Created FoodTruck app with admin root: %s" % root_dir)

    return app