airflow.providers.fab.www.extensions.init_appbuilder¶
属性¶
类¶
这是所有框架的基类。 |
函数¶
|
将从字符串路径动态导入一个类。 |
|
初始化 Flask App Builder。 |
模块内容¶
- airflow.providers.fab.www.extensions.init_appbuilder.dynamic_class_import(class_path)[source]¶
将从字符串路径动态导入一个类。
- 参数:
class_path – 包含类路径的字符串
- 返回:
类
- class airflow.providers.fab.www.extensions.init_appbuilder.AirflowAppBuilder(app=None, session=None, menu=None, indexview=None, base_template='airflow/main.html', static_folder='static/appbuilder', static_url_path='/appbuilder', enable_plugins=False)[source]¶
这是所有框架的基类。
- baseviews: list[flask_appbuilder.BaseView | sqlalchemy.orm.Session] = [][source]¶
- add_view(baseview, name, href='', icon='', label='', category='', category_icon='', category_label='', menu_cond=None)[source]¶
使用此方法添加与菜单关联的视图。
- 参数:
baseview – 一个已实例化或未实例化的 BaseView 类型类。如果需要,此方法将为你实例化该类。
name – 用于标识菜单的字符串名称。
href – 覆盖为菜单生成的链接。可以使用 URL 字符串或端点名称,如果未提供,将使用视图中的 default_view 作为链接。
icon – Font-Awesome 图标名称,可选。
label – 将显示在菜单上的标签,如果省略,将使用参数 name。
category – 菜单所属类别,如果未提供,视图将作为顶级菜单显示。
category_icon – 类别的 Font-Awesome 图标名称,可选。
category_label – 将显示在菜单上的标签,如果省略,将使用参数 name。
menu_cond – 如果是可调用对象,
menu_cond
将在构建菜单项时被调用。如果返回True
,则此链接将成为菜单的一部分。否则,它将不包含在菜单项中。默认为None
,表示该项将始终显示。
示例
appbuilder = AppBuilder(app, db) # Register a view, rendering a top menu without icon. appbuilder.add_view(MyModelView(), "My View") # or not instantiated appbuilder.add_view(MyModelView, "My View") # Register a view, a submenu "Other View" from "Other" with a phone icon. appbuilder.add_view(MyOtherModelView, "Other View", icon="fa-phone", category="Others") # Register a view, with category icon and translation. appbuilder.add_view( YetOtherModelView, "Other View", icon="fa-phone", label=_("Other View"), category="Others", category_icon="fa-envelop", category_label=_("Other View"), ) # Register a view whose menu item will be conditionally displayed appbuilder.add_view( YourFeatureView, "Your Feature", icon="fa-feature", label=_("Your Feature"), menu_cond=lambda: is_feature_enabled("your-feature"), ) # Add a link appbuilder.add_link("google", href="www.google.com", icon="fa-google-plus")
- add_link(name, href, icon='', label='', category='', category_icon='', category_label='', baseview=None, cond=None)[source]¶
使用此方法将自己的链接添加到菜单。
- 参数:
name – 用于标识菜单的字符串名称。
href – 覆盖为菜单生成的链接。可以使用 URL 字符串或端点名称
icon – Font-Awesome 图标名称,可选。
label – 将显示在菜单上的标签,如果省略,将使用参数 name。
category – 菜单所属类别,如果未提供,视图将作为顶级菜单显示。
category_icon – 类别的 Font-Awesome 图标名称,可选。
category_label – 将显示在菜单上的标签,如果省略,将使用参数 name。
baseview – 已实例化的 BaseView 类型类。
cond – 如果是可调用对象,
cond
将在构建菜单项时被调用。如果返回True
,则此链接将成为菜单的一部分。否则,它将不包含在菜单项中。默认为None
,表示该项将始终显示。
- add_separator(category, cond=None)[source]¶
在菜单中添加分隔符,你将按顺序创建菜单。
- 参数:
category – 分隔符将包含在的菜单类别。
cond – 如果是可调用对象,
cond
将在构建菜单项时被调用。如果返回True
,则此分隔符将成为菜单的一部分。否则,它将不包含在菜单项中。默认为None
,表示分隔符将始终显示。
添加你的视图而不创建菜单。
- 参数:
baseview – 已实例化的 BaseView 类型类。
- airflow.providers.fab.www.extensions.init_appbuilder.init_appbuilder(app, enable_plugins)[source]¶
初始化 Flask App Builder。