【问题标题】:Superset customization. extend/modify超集定制。扩展/修改
【发布时间】:2019-01-17 11:35:00
【问题描述】:

我正在尝试扩展/修改 Superset。我的目标是在“列表列”选项卡中添加带有附加属性的“编辑表”表单的修改版本。目前有[Column, Verbose Name, Type, Groupable, Filterable, Is temporal]。我想再添加几个,例如“Is target”、“Is predictor”等。

我不确定执行此操作的最佳方法。

我认为尝试使用 Flask 蓝图来做这件事是可行的方法,但文档中只有一个非常基本的“hello world”类型示例:

from flask import Blueprint
simple_page = Blueprint('simple_page', __name__,
                        template_folder='templates',
                        url_prefix='/simple_page')
@simple_page.route('/', defaults={'page': 'index'})
@simple_page.route('/<page>')
def show(page):
    return "Ok"

我如何设置一个蓝图来继承 Superset 中的几乎所有内容,但添加该表单的修改版本以及必要的修改以将新列保存到数据库中?

我试图避免分叉和创建我自己的 Superset 修改版本,因为这将难以维护。

【问题讨论】:

  • 你好。你找到解决方案了吗?我调查了一点superset 定制。看起来很耗时
  • 不,我放弃了超集。
  • 我为我的坚持深表歉意。你能推荐一些好的工具吗?我见过redash。但看起来与superset 相同。我需要infogram 之类的东西,但可以将它部署在我自己的服务器上。
  • 我仍在评估多种选择。但是,以下 Danila Ganchar 的回答看起来非常有用。任何潜在的解决方案都需要进行一些修改以供高级使用。
  • 谢谢。祝你好运;)

标签: flask superset apache-superset


【解决方案1】:

不确定这是否是您需要的,但我认为我的回答可以节省一些时间并得出一些结论,因为网络上几乎没有示例。我的示例是什么:1) 在主菜单中添加自定义下拉菜单2) 更改列编辑字段。

我找到了hook,它提供了在应用运行时做某事的可能性。 我还发现在你的情况下工作TableModelView。但是columns tab 使用TableColumnInlineView 工作。项目结构:

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

superset_config.py在运行应用时自动工作:

from flask import Blueprint, render_template, g, redirect
from flask_appbuilder import has_access


def 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 run
FLASK_APP_MUTATOR = flask_app_mutator

# just a new blue print for processing new menu item
example_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]

从存储superset_config.py的目录运行我们的应用程序,登录,打开一些表进行编辑(例如:http://0.0.0.0:8088/tablemodelview/edit/1)。您将看到我们视图的字段已更改 + 新菜单项:

如果您打开我们的菜单项(或http://0.0.0.0:8088/example),您将看到superset 的基本布局:

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 %}

但我确信定制很耗时。一些组件使用builded js packages 工作。我不能保证 UIbackend 修改后会正常工作。

无论如何,我希望这会对某人有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-04
    • 2013-02-26
    • 1970-01-01
    • 2014-11-08
    相关资源
    最近更新 更多