Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions superset/connectors/druid/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ class DruidClusterModelView(SupersetModelView, DeleteMixin, YamlExportMixin):
),
}

yaml_dict_key = "databases"

edit_form_extra_fields = {
"cluster_name": QuerySelectField(
"Cluster",
Expand Down
10 changes: 9 additions & 1 deletion superset/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import logging
import traceback
from datetime import datetime
from typing import Any, Dict
from typing import Any, Dict, Optional

import simplejson as json
import yaml
Expand Down Expand Up @@ -208,12 +208,20 @@ def validate_json(form, field):


class YamlExportMixin(object):
yaml_dict_key: Optional[str] = None
"""
Override this if you a dict response instead, with a certain key.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: ..if you want a dict response..

Used on DatabaseView for cli compatibility
"""

@action("yaml_export", __("Export to YAML"), __("Export to YAML?"), "fa-download")
def yaml_export(self, items):
if not isinstance(items, list):
items = [items]

data = [t.export_to_dict() for t in items]
if self.yaml_dict_key:
data = {self.yaml_dict_key: data}
return Response(
yaml.safe_dump(data),
headers=generate_download_headers("yaml"),
Expand Down
2 changes: 2 additions & 0 deletions superset/views/database/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class DatabaseView(DatabaseMixin, SupersetModelView, DeleteMixin, YamlExportMixi
edit_template = "superset/models/database/edit.html"
validators_columns = {"sqlalchemy_uri": [sqlalchemy_uri_form_validator]}

yaml_dict_key = "databases"

def _delete(self, pk):
DeleteMixin._delete(self, pk)

Expand Down