示例#1
0
文件: v0.py 项目: ws1993/superset
def import_dashboards(
    session: Session,
    content: str,
    database_id: Optional[int] = None,
    import_time: Optional[int] = None,
) -> None:
    """Imports dashboards from a stream to databases"""
    current_tt = int(time.time())
    import_time = current_tt if import_time is None else import_time
    data = json.loads(content, object_hook=decode_dashboards)
    if not data:
        raise DashboardImportException(_("No data in file"))
    dataset_id_mapping: Dict[int, int] = {}
    for table in data["datasources"]:
        new_dataset_id = import_dataset(table,
                                        database_id,
                                        import_time=import_time)
        params = json.loads(table.params)
        dataset_id_mapping[params["remote_id"]] = new_dataset_id

    session.commit()
    for dashboard in data["dashboards"]:
        import_dashboard(dashboard,
                         dataset_id_mapping,
                         import_time=import_time)
    session.commit()
示例#2
0
def import_dashboards(
    data_stream: BytesIO,
    database_id: Optional[int] = None,
    import_time: Optional[int] = None,
) -> None:
    """Imports dashboards from a stream to databases"""
    current_tt = int(time.time())
    import_time = current_tt if import_time is None else import_time
    data = json.loads(data_stream.read(), object_hook=decode_dashboards)
    if not data:
        raise DashboardImportException(_("No data in file"))
    for table in data["datasources"]:
        type(table).import_obj(table, database_id, import_time=import_time)
    db.session.commit()
    for dashboard in data["dashboards"]:
        Dashboard.import_obj(dashboard, import_time=import_time)
    db.session.commit()