Skip to content

Commit

Permalink
Allow running Flask Blueprints alongside Superset (#2337)
Browse files Browse the repository at this point in the history
* Allowing environments to import Blueprints

* Docs entry

* Fix typos
  • Loading branch information
mistercrunch authored Mar 4, 2017
1 parent e35016f commit f6ffc00
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
25 changes: 25 additions & 0 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -377,3 +377,28 @@ your environment.::
npm run build
cd $SUPERSET_HOME
python setup.py install


Blueprints
----------

`Blueprints are Flask's reusable apps <http://flask.pocoo.org/docs/0.12/blueprints/>`_.
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('/<page>')
def show(page):
return "Ok"

BLUEPRINTS = [simple_page]
8 changes: 8 additions & 0 deletions superset/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
5 changes: 5 additions & 0 deletions superset/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f6ffc00

Please sign in to comment.