123456789101112131415161718192021222324252627282930313233343536373839 |
- # pylint: disable=C,R,W
- from __future__ import absolute_import
- from __future__ import division
- from __future__ import print_function
- from __future__ import unicode_literals
- import json
- import logging
- import time
- from superset import utils
- from superset.models.core import Dashboard
- 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=utils.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()
- def export_dashboards(session):
- """Returns all dashboards metadata as a json dump"""
- logging.info('Starting export')
- dashboards = session.query(Dashboard)
- dashboard_ids = []
- for dashboard in dashboards:
- dashboard_ids.append(dashboard.id)
- data = Dashboard.export_dashboards(dashboard_ids)
- return data
|