From f6ffc007481c658293ae209982dfc369c0f82f95 Mon Sep 17 00:00:00 2001 From: Maxime Beauchemin Date: Fri, 3 Mar 2017 17:09:54 -0800 Subject: [PATCH] Allow running Flask Blueprints alongside Superset (#2337) * Allowing environments to import Blueprints * Docs entry * Fix typos --- docs/installation.rst | 25 +++++++++++++++++++++++++ superset/__init__.py | 8 ++++++++ superset/config.py | 5 +++++ 3 files changed, 38 insertions(+) diff --git a/docs/installation.rst b/docs/installation.rst index e6aaa5fa9e9a2..e85fd01765356 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -377,3 +377,28 @@ your environment.:: npm run build cd $SUPERSET_HOME python setup.py install + + +Blueprints +---------- + +`Blueprints are Flask's reusable apps `_. +Superset allows you to specify an array of Blueprints +an array of Blueprints in your ``superset_config`` module. Here's +an example on how this can work with a simple Blueprint. By doing +so, you can expect Superset to serve a page that says "OK" +at the ``/simple_page`` url. This can allow you to run other things such +as custom data visualization applications alongside Superset, on the +same server. + +..code :: + + from flask import Blueprint + simple_page = Blueprint('simple_page', __name__, + template_folder='templates') + @simple_page.route('/', defaults={'page': 'index'}) + @simple_page.route('/') + def show(page): + return "Ok" + + BLUEPRINTS = [simple_page] diff --git a/superset/__init__.py b/superset/__init__.py index f3d8795c02d45..bad241e3fccb0 100644 --- a/superset/__init__.py +++ b/superset/__init__.py @@ -29,6 +29,14 @@ app.config.from_object(CONFIG_MODULE) conf = app.config +for bp in conf.get('BLUEPRINTS'): + try: + print("Registering blueprint: '{}'".format(bp.name)) + app.register_blueprint(bp) + except Exception as e: + print("blueprint registration failed") + logging.exception(e) + if conf.get('SILENCE_FAB'): logging.getLogger('flask_appbuilder').setLevel(logging.ERROR) diff --git a/superset/config.py b/superset/config.py index 293fa485cdfb7..b2bc460c4f430 100644 --- a/superset/config.py +++ b/superset/config.py @@ -286,6 +286,11 @@ class CeleryConfig(object): # permission management SILENCE_FAB = True + +# Integrate external Blueprints to the app by passing them to your +# configuration. These blueprints will get integrated in the app +BLUEPRINTS = [] + try: if CONFIG_PATH_ENV_VAR in os.environ: # Explicitly import config module that is not in pythonpath; useful