Example #1
0
def create_app(**config):
    app = Flask(__name__, static_folder='../spendb.ui')
    app.config.from_object(default_settings)
    app.config.from_envvar('SPENDB_SETTINGS', silent=True)
    app.config.update(config)

    app.jinja_options['extensions'].extend([
        formencode_jinja2.formfill,
        'jinja2.ext.i18n'
    ])

    db.init_app(app)
    babel.init_app(app)
    cache.init_app(app)
    mail.init_app(app)
    assets.init_app(app)
    login_manager.init_app(app)
    data_manager.init_app(app)
    pages.init_app(app)
    migrate.init_app(app, db, directory=app.config.get('ALEMBIC_DIR'))
    cors.init_app(app, resources=r'/api/*', supports_credentials=True,
                  methods=['GET', 'HEAD', 'OPTIONS'])

    ws = Workspace()
    ext.model_provider("spending", metadata={})
    ext.store("spending")
    ws.register_default_store('spending', model_provider='spending')
    app.cubes_workspace = ws
    return app
Example #2
0
def create_app(**config):
    app = Flask(__name__)
    app.config.from_object(default_settings)
    app.config.from_envvar('SPENDB_SETTINGS', silent=True)
    app.config.update(config)

    app.jinja_options['extensions'].extend([
        formencode_jinja2.formfill,
        'jinja2.ext.i18n'
    ])

    db.init_app(app)
    babel.init_app(app)
    cache.init_app(app)
    mail.init_app(app)
    assets.init_app(app)
    login_manager.init_app(app)
    data_manager.init_app(app)
    pages.init_app(app)
    migrate.init_app(app, db, directory=app.config.get('ALEMBIC_DIR'))

    from spendb.model.provider import SpendingStore
    extensions.store.extensions['spending'] = SpendingStore
    app.cubes_workspace = Workspace()
    app.cubes_workspace.register_default_store('spending')
    return app
Example #3
0
def create_app(**config):
    app = Flask(__name__)
    app.url_rule_class = NamespaceRouteRule
    app.url_map.converters["fmt"] = FormatConverter
    app.url_map.converters["nodot"] = NoDotConverter

    app.config.from_object(default_settings)
    app.config.from_envvar("OPENSPENDING_SETTINGS", silent=True)
    app.config.update(config)

    app.jinja_options["extensions"].extend([formencode_jinja2.formfill, "jinja2.ext.i18n"])

    db.init_app(app)
    cache.init_app(app)
    mail.init_app(app)
    assets.init_app(app)
    login_manager.init_app(app)
    configure_uploads(app, (sourcefiles,))

    @app.before_request
    def require_basic_auth(*args, **kwargs):
        LOCKDOWN_FORCE = app.config["LOCKDOWN_FORCE"]
        if not current_user.is_authenticated() and request.path not in ["/lockdown", "/__ping__"] and LOCKDOWN_FORCE:
            return redirect("/lockdown", code=302)
        from openspending.model.search import SearchForm

        g.search_form = SearchForm()
        if request.method == "POST" and request.path not in ["/lockdown"]:
            token = session.get("csrf_token", None)
            resquesttoken = request.form.get("csrf_token", None)
            if request.json and not resquesttoken:
                resquesttoken = request.json.get("csrf_token")
            if not token or resquesttoken != token:
                abort(403)

    with app.app_context():
        app.cubes_workspace = Workspace()

        app.cubes_workspace.register_default_store("OpenSpendingStore")

    return app