Пример #1
0
    def _export(model: Slice,
                export_related: bool = True) -> Iterator[Tuple[str, str]]:
        chart_slug = secure_filename(model.slice_name)
        file_name = f"charts/{chart_slug}_{model.id}.yaml"

        payload = model.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
        payload = {
            key: value
            for key, value in payload.items() if key not in REMOVE_KEYS
        }

        if payload.get("params"):
            try:
                payload["params"] = json.loads(payload["params"])
            except json.decoder.JSONDecodeError:
                logger.info("Unable to decode `params` field: %s",
                            payload["params"])

        payload["version"] = EXPORT_VERSION
        if model.table:
            payload["dataset_uuid"] = str(model.table.uuid)

        file_content = yaml.safe_dump(payload, sort_keys=False)
        yield file_name, file_content

        if model.table and export_related:
            yield from ExportDatasetsCommand([model.table.id]).run()
Пример #2
0
    def export_chart(chart: Slice) -> Iterator[Tuple[str, str]]:
        chart_slug = sanitize(chart.slice_name)
        file_name = f"charts/{chart_slug}.yaml"

        payload = chart.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 in REMOVE_KEYS:
            del payload[key]
        if "params" in payload:
            try:
                payload["params"] = json.loads(payload["params"])
            except json.decoder.JSONDecodeError:
                pass

        payload["version"] = IMPORT_EXPORT_VERSION
        if chart.table:
            payload["dataset_uuid"] = str(chart.table.uuid)

        file_content = yaml.safe_dump(payload, sort_keys=False)
        yield file_name, file_content

        if chart.table:
            yield from ExportDatasetsCommand([chart.table.id]).run()