Export dashboards to ZIP file
(dashboard_file: Optional[str] = None)
| 272 | "--dashboard-file", "-f", help="Specify the the file to export to", |
| 273 | ) |
| 274 | def export_dashboards(dashboard_file: Optional[str] = None) -> None: |
| 275 | """Export dashboards to ZIP file""" |
| 276 | # pylint: disable=import-outside-toplevel |
| 277 | from superset.dashboards.commands.export import ExportDashboardsCommand |
| 278 | from superset.models.dashboard import Dashboard |
| 279 | |
| 280 | g.user = security_manager.find_user(username="admin") |
| 281 | |
| 282 | dashboard_ids = [id_ for (id_,) in db.session.query(Dashboard.id).all()] |
| 283 | timestamp = datetime.now().strftime("%Y%m%dT%H%M%S") |
| 284 | root = f"dashboard_export_{timestamp}" |
| 285 | dashboard_file = dashboard_file or f"{root}.zip" |
| 286 | |
| 287 | try: |
| 288 | with ZipFile(dashboard_file, "w") as bundle: |
| 289 | for file_name, file_content in ExportDashboardsCommand( |
| 290 | dashboard_ids |
| 291 | ).run(): |
| 292 | with bundle.open(f"{root}/{file_name}", "w") as fp: |
| 293 | fp.write(file_content.encode()) |
| 294 | except Exception: # pylint: disable=broad-except |
| 295 | logger.exception( |
| 296 | "There was an error when exporting the dashboards, please check " |
| 297 | "the exception traceback in the log" |
| 298 | ) |
| 299 | |
| 300 | @superset.command() |
| 301 | @with_appcontext |
nothing calls this directly
no test coverage detected