对话框API

Frappe 提供了一组标准、交互式且灵活的对话框,易于配置和使用。此外,还有一个更全面的 Javascript API。

frappe.msgprint

frappe.msgprint(msg, title, raise_exception, as_table, as_list, indicator, primary_action, is_minimizable, wide, realtime)

此方法仅在请求/响应周期内有效。它会向发起请求并登录 Desk 的用户显示一条消息。

参数列表包括:

  • msg:要显示的消息
  • title:模态框的标题
  • as_table:如果 msg 是列表的列表,则渲染为 HTML 表格
  • as_list:如果 msg 是列表,则渲染为 HTML 无序列表
  • primary_action:绑定一个主要的服务器端/客户端操作。
  • raise_exception:异常
  • is_wide:显示一个宽模态框
  • is_minimizable:允许用户最小化模态框
  • realtime:使用 websocket 立即发布,而不是添加到响应消息日志中
frappe.msgprint(
    msg='This file does not exist',
    title='Error',
    raise_exception=FileNotFoundError
)

frappe.msgprint

primary_action 可以包含一个 server_action client_side 操作,该操作必须包含指向相应方法的点分路径。JavaScript 函数必须是全局可用的函数。您还可以传递 hide_on_success 以在操作成功完成后关闭消息。

# msgprint with server and client side action
frappe.msgprint(msg='This file does not exist',
    title='Error',
    raise_exception=FileNotFoundError
    primary_action={
        'label': _('Perform Action'),
        'server_action': 'dotted.path.to.server.method',
        'client_action': 'dotted.path.to.client.method',
        'hide_on_success': True,
        'args': args
    }
)

带主要操作的 frappe.msgprint

frappe.throw

frappe.throw(msg, exc, title, is_minimizable, wide, as_list, primary_action)

此方法将引发异常并在 Desk 中显示消息。它本质上是 frappe.msgprint 的封装。

exc 可以传递一个可选的异常。默认情况下,它将引发一个 ValidationError 异常。

frappe.throw(
    title='Error',
    msg='This file does not exist',
    exc=FileNotFoundError
)

frappe.throw