airflow.providers.fab.www.extensions.init_appbuilder

属性

log

AirflowAppBuilder

这是所有框架的基类。

函数

dynamic_class_import(class_path)

将从字符串路径动态导入一个类。

init_appbuilder(app, enable_plugins)

初始化 Flask App Builder

模块内容

airflow.providers.fab.www.extensions.init_appbuilder.log[source]
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]
app = None[source]
session = None[source]
sm: flask_appbuilder.security.manager.BaseSecurityManager[source]
bm = None[source]
addon_managers: dict[source]
menu = None[source]
indexview = None[source]
static_folder = None[source]
static_url_path = None[source]
template_filters = None[source]
base_template = 'airflow/main.html'[source]
enable_plugins = False[source]
update_perms = True[source]
auth_rate_limited = True[source]
auth_rate_limit[source]
init_app(app, session)[source]

将初始化 Flask 应用,支持应用工厂模式。

参数:
  • app

  • session – SQLAlchemy 会话

property get_app[source]

获取当前或已配置的 Flask 应用。

返回:

Flask 应用

property get_session[source]

获取当前的 SQLAlchemy 会话。

返回:

SQLAlchemy 会话

property app_name[source]

获取应用名称。

返回:

包含应用名称的字符串

property app_theme[source]

获取应用主题名称。

返回:

应用主题名称字符串

property app_icon[source]

获取应用图标位置。

返回:

包含相对应用图标位置的字符串

property languages[source]
property version[source]

获取当前的 F.A.B. 版本。

返回:

包含当前 F.A.B. 版本的字符串

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")

使用此方法将自己的链接添加到菜单。

参数:
  • 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,表示分隔符将始终显示。

add_view_no_menu(baseview, endpoint=None, static_folder=None)[source]

添加你的视图而不创建菜单。

参数:

baseview – 已实例化的 BaseView 类型类。

property get_url_for_index[source]
get_url_for_login_with(next_url=None)[source]
property get_url_for_login[source]
get_url_for_locale(lang)[source]
add_limits(baseview)[source]
add_permissions(update_perms=False)[source]
register_blueprint(baseview, endpoint=None, static_folder=None)[source]
airflow.providers.fab.www.extensions.init_appbuilder.init_appbuilder(app, enable_plugins)[source]

初始化 Flask App Builder

此条目是否有帮助?