Superset customization. extend/modify Superset customization. extend/modify flask flask

Superset customization. extend/modify


Not sure if this is what you need, but I think my answer could save someone time and draw some conclusions because there are almost no examples on the net. What do my example: 1) add custom drop-down into main menu 2) change column edit fields.

I found hook which provide possibility to do something when app run. Also I found that in your case works TableModelView. But columns tab works using TableColumnInlineView. Structure of project:

├── superset_config.py├── templates│   ├── example.html

superset_config.py works automatically when run app:

from flask import Blueprint, render_template, g, redirectfrom flask_appbuilder import has_accessdef flask_app_mutator(app):    # my version of superset v0.29    # be careful with imports! they are should be inside functions!    # in other case config will not work    from superset import appbuilder    from superset.connectors.sqla.views import TableModelView, TableColumnInlineView    # found our view and change something...    for v in appbuilder.baseviews:        if isinstance(v, TableModelView):            table_columns = v.related_views[0]  # type: TableColumnInlineView            table_columns.edit_columns = ['column_name', 'type']    # add a new menu item    appbuilder.add_link(        'example',        label='example',        href='/example',        category_icon='fa-file-text-o',        category='Example')# register our mutator - he will be called when app runFLASK_APP_MUTATOR = flask_app_mutator# just a new blue print for processing new menu itemexample_bp = Blueprint(    'example',    __name__,    template_folder='templates',    static_url_path='/static/report')@example_bp.route('/example')def example():    # as I wrote above - be careful with imports...    from superset import appbuilder    if not g.user or not g.user.get_id():        return redirect(appbuilder.get_url_for_login)    return render_template('example.html', appbuilder=appbuilder)BLUEPRINTS = [example_bp]

Run our app from directory where stored superset_config.py, login, open some table for edit (example: http://0.0.0.0:8088/tablemodelview/edit/1). You will see that fields of our view was changed + new menu item:

edit columns

You will see the basic layout of the superset if you open our menu item(or http://0.0.0.0:8088/example):custom page

example.html:

{% extends 'superset/basic.html' %}{% block body %}<div>Hello world</div>{% endblock %}{% block tail_js %}    {{ super() }}    <script type="text/javascript" src="{{ url_for('static', filename='appbuilder/js/jquery-latest.js') }}"></script>    <script type="text/javascript" src="{{ url_for('static', filename='appbuilder/js/bootstrap.min.js') }}"></script>{% endblock %}

But I'm sure that customization is time consuming. Some components works using builded js packages. I can't guarantee that UI will work fine after backend mods.

In any case, I hope this will help someone.