예제 #1
0
def import_dashboards(session, data_stream):
    """Imports dashboards from a stream to databases"""
    data = json.loads(data_stream.read(), object_hook=decode_dashboards)
    # TODO: import DRUID datasources
    for table in data["datasources"]:
        type(table).import_obj(table)
    session.commit()
    for dashboard in data["dashboards"]:
        Dashboard.import_obj(dashboard)
    session.commit()
예제 #2
0
def import_dashboards(session, data_stream, import_time=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)
    # TODO: import DRUID datasources
    for table in data['datasources']:
        type(table).import_obj(table, import_time=import_time)
    session.commit()
    for dashboard in data['dashboards']:
        Dashboard.import_obj(dashboard, import_time=import_time)
    session.commit()
예제 #3
0
def import_dashboards(session, data_stream, import_time=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)
    # TODO: import DRUID datasources
    for table in data['datasources']:
        type(table).import_obj(table, import_time=import_time)
    session.commit()
    for dashboard in data['dashboards']:
        Dashboard.import_obj(
            dashboard, import_time=import_time)
    session.commit()
예제 #4
0
def create_dashboard(title=None, slices=None, tags=None):
    """Create a new test dashboard (and slice and table if needed)"""

    if tags is None:
        tags = ['test']

    if title is None:
        title = "dashboard-%s" % uuid.uuid4()

    if slices is None:
        slices = [new_slice(tags=tags)]

    dashboard = Dashboard(
        dashboard_title=title,
        slug=title.lower(),
        slices=slices,
        position_json=json.dumps(dict(size_y=2, size_x=2)),
        json_metadata=json.dumps(dict(tags=tags)),
    )

    # Return imported obj
    dashboard = superset.db.session.query(Dashboard).filter_by(
        id=Dashboard.import_obj(dashboard)).first()
    dashboard.published = True
    superset.db.session.merge(dashboard)
    superset.db.session.commit()

    return dashboard
예제 #5
0
def import_dashboard_json(session, data, import_time=None):
    current_tt = int(time.time())
    import_time = current_tt if import_time is None else import_time
    dashboard = data['dashboards'][0]
    update_slice_options(dashboard.slices)
    dash_id = Dashboard.import_obj(dashboard, import_time=import_time)
    session.commit()
    return dash_id