From 988fc340e39433b1965dabd2f93ae1b695ad9f16 Mon Sep 17 00:00:00 2001 From: Maxime Beauchemin Date: Wed, 19 Apr 2017 14:12:04 -0700 Subject: [PATCH 1/2] Showing slices on datasource edit form --- superset/connectors/druid/models.py | 5 +++++ superset/connectors/druid/views.py | 11 ++++++++++- superset/connectors/sqla/models.py | 5 +++++ superset/connectors/sqla/views.py | 11 ++++++++++- 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/superset/connectors/druid/models.py b/superset/connectors/druid/models.py index c69bc1783357..422b009e302b 100644 --- a/superset/connectors/druid/models.py +++ b/superset/connectors/druid/models.py @@ -331,6 +331,11 @@ class DruidDatasource(Model, BaseDatasource): 'datasource_name', 'is_hidden', 'description', 'default_endpoint', 'cluster_name', 'offset', 'cache_timeout', 'params' ) + slices = relationship( + 'Slice', + primaryjoin=( + "DruidDatasource.id == foreign(Slice.datasource_id) and " + "Slice.datasource_type == 'druid'")) @property def database(self): diff --git a/superset/connectors/druid/views.py b/superset/connectors/druid/views.py index bfd13df5cd00..68047dd05de7 100644 --- a/superset/connectors/druid/views.py +++ b/superset/connectors/druid/views.py @@ -155,7 +155,7 @@ class DruidDatasourceModelView(SupersetModelView, DeleteMixin): # noqa 'datasource_link', 'changed_on_', 'offset'] related_views = [DruidColumnInlineView, DruidMetricInlineView] edit_columns = [ - 'datasource_name', 'cluster', 'description', 'owner', + 'datasource_name', 'cluster', 'slices', 'description', 'owner', 'is_hidden', 'filter_select_enabled', 'fetch_values_from', 'default_endpoint', 'offset', 'cache_timeout'] @@ -164,6 +164,14 @@ class DruidDatasourceModelView(SupersetModelView, DeleteMixin): # noqa page_size = 500 base_order = ('datasource_name', 'asc') description_columns = { + 'slices': _( + "The list of slices associated with this table. By " + "altering this datasource, you may change how these associated " + "slices behave. " + "Also note that slices need to point to a datasource, so " + "this form will fail at saving if removing slices from a " + "datasource. If you want to change the datasource for a slice, " + "overwrite the slice from the 'explore view'"), 'offset': _("Timezone offset (in hours) for this datasource"), 'description': Markup( "Supports Date: Wed, 19 Apr 2017 16:52:28 -0700 Subject: [PATCH 2/2] fixing build --- superset/models/core.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/superset/models/core.py b/superset/models/core.py index 93b283d5261f..2a46e7dda086 100644 --- a/superset/models/core.py +++ b/superset/models/core.py @@ -48,9 +48,10 @@ def set_related_perm(mapper, connection, target): # noqa src_class = target.cls_model id_ = target.datasource_id - ds = db.session.query(src_class).filter_by(id=int(id_)).first() - if ds: - target.perm = ds.perm + if id_: + ds = db.session.query(src_class).filter_by(id=int(id_)).first() + if ds: + target.perm = ds.perm class Url(Model, AuditMixinNullable):