You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2020/10/22 18:58:55 UTC

[GitHub] [incubator-superset] hughhhh commented on a change in pull request #11351: feat: export dashboards as ZIP files

hughhhh commented on a change in pull request #11351:
URL: https://github.com/apache/incubator-superset/pull/11351#discussion_r510388376



##########
File path: superset/dashboards/commands/export.py
##########
@@ -0,0 +1,80 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+# isort:skip_file
+
+import json
+from typing import Iterator, List, Tuple
+
+import yaml
+
+from superset.commands.base import BaseCommand
+from superset.charts.commands.export import ExportChartsCommand
+from superset.dashboards.commands.exceptions import DashboardNotFoundError
+from superset.dashboards.dao import DashboardDAO
+from superset.models.dashboard import Dashboard
+from superset.utils.dict_import_export import IMPORT_EXPORT_VERSION, sanitize
+
+
+# keys stored as JSON are loaded and the prefix/suffix removed
+JSON_KEYS = {"position_json": "position", "json_metadata": "metadata"}
+
+
+class ExportDashboardsCommand(BaseCommand):
+    def __init__(self, dashboard_ids: List[int]):
+        self.dashboard_ids = dashboard_ids
+
+        # this will be set when calling validate()
+        self._models: List[Dashboard] = []
+
+    @staticmethod
+    def export_dashboard(dashboard: Dashboard) -> Iterator[Tuple[str, str]]:
+        dashboard_slug = sanitize(dashboard.dashboard_title)
+        file_name = f"dashboards/{dashboard_slug}.yaml"
+
+        payload = dashboard.export_to_dict(
+            recursive=False,
+            include_parent_ref=False,
+            include_defaults=True,
+            export_uuids=True,
+        )
+        # TODO (betodealmeida): move this logic to export_to_dict once this
+        # becomes the default export endpoint
+        for key, new_name in JSON_KEYS.items():
+            if payload.get(key):
+                try:
+                    payload[new_name] = json.loads(payload.pop(key))
+                except json.decoder.JSONDecodeError:
+                    pass

Review comment:
       ```suggestion
   		logger.info("Unable to decode `extra` field: %s", payload["extra"])
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org