superset-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From johnbod...@apache.org
Subject [incubator-superset] branch master updated: [connectors] Make cluster/database and datasource/table unselectable in CRUD view (#7073)
Date Mon, 10 Jun 2019 17:25:32 GMT
This is an automated email from the ASF dual-hosted git repository.

johnbodley pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git


The following commit(s) were added to refs/heads/master by this push:
     new c6179b1  [connectors] Make cluster/database and datasource/table unselectable in
CRUD view (#7073)
c6179b1 is described below

commit c6179b195f8c5f482928055803344a0e2f313bcc
Author: John Bodley <4567245+john-bodley@users.noreply.github.com>
AuthorDate: Mon Jun 10 10:25:13 2019 -0700

    [connectors] Make cluster/database and datasource/table unselectable in CRUD view (#7073)
---
 superset/connectors/druid/views.py | 32 ++++++++++++++++++++++++++++++++
 superset/connectors/sqla/views.py  | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 64 insertions(+)

diff --git a/superset/connectors/druid/views.py b/superset/connectors/druid/views.py
index 99923e0..103dd25 100644
--- a/superset/connectors/druid/views.py
+++ b/superset/connectors/druid/views.py
@@ -21,10 +21,12 @@ import logging
 
 from flask import flash, Markup, redirect
 from flask_appbuilder import CompactCRUDMixin, expose
+from flask_appbuilder.fieldwidgets import Select2Widget
 from flask_appbuilder.models.sqla.interface import SQLAInterface
 from flask_appbuilder.security.decorators import has_access
 from flask_babel import gettext as __
 from flask_babel import lazy_gettext as _
+from wtforms.ext.sqlalchemy.fields import QuerySelectField
 
 from superset import appbuilder, db, security_manager
 from superset.connectors.base.views import DatasourceModelView
@@ -76,6 +78,17 @@ class DruidColumnInlineView(CompactCRUDMixin, SupersetModelView):  # noqa
             True),
     }
 
+    add_form_extra_fields = {
+        'datasource': QuerySelectField(
+            'Datasource',
+            query_factory=lambda: db.session().query(models.DruidDatasource),
+            allow_blank=True,
+            widget=Select2Widget(extra_classes='readonly'),
+        ),
+    }
+
+    edit_form_extra_fields = add_form_extra_fields
+
     def pre_update(self, col):
         # If a dimension spec JSON is given, ensure that it is
         # valid JSON and that `outputName` is specified
@@ -145,6 +158,17 @@ class DruidMetricInlineView(CompactCRUDMixin, SupersetModelView):  #
noqa
         'is_restricted': _('Is Restricted'),
     }
 
+    add_form_extra_fields = {
+        'datasource': QuerySelectField(
+            'Datasource',
+            query_factory=lambda: db.session().query(models.DruidDatasource),
+            allow_blank=True,
+            widget=Select2Widget(extra_classes='readonly'),
+        ),
+    }
+
+    edit_form_extra_fields = add_form_extra_fields
+
     def post_add(self, metric):
         if metric.is_restricted:
             security_manager.add_permission_view_menu('metric_access', metric.get_perm())
@@ -201,6 +225,14 @@ class DruidClusterModelView(SupersetModelView, DeleteMixin, YamlExportMixin):
 #
         ),
     }
 
+    edit_form_extra_fields = {
+        'cluster_name': QuerySelectField(
+            'Cluster',
+            query_factory=lambda: db.session().query(models.DruidCluster),
+            widget=Select2Widget(extra_classes='readonly'),
+        ),
+    }
+
     def pre_add(self, cluster):
         security_manager.add_permission_view_menu('database_access', cluster.perm)
 
diff --git a/superset/connectors/sqla/views.py b/superset/connectors/sqla/views.py
index 2edf949..e6c0029 100644
--- a/superset/connectors/sqla/views.py
+++ b/superset/connectors/sqla/views.py
@@ -21,10 +21,12 @@ import logging
 from flask import flash, Markup, redirect
 from flask_appbuilder import CompactCRUDMixin, expose
 from flask_appbuilder.actions import action
+from flask_appbuilder.fieldwidgets import Select2Widget
 from flask_appbuilder.models.sqla.interface import SQLAInterface
 from flask_appbuilder.security.decorators import has_access
 from flask_babel import gettext as __
 from flask_babel import lazy_gettext as _
+from wtforms.ext.sqlalchemy.fields import QuerySelectField
 
 from superset import appbuilder, db, security_manager
 from superset.connectors.base.views import DatasourceModelView
@@ -107,6 +109,17 @@ class TableColumnInlineView(CompactCRUDMixin, SupersetModelView):  #
noqa
         'type': _('Type'),
     }
 
+    add_form_extra_fields = {
+        'table': QuerySelectField(
+            'Table',
+            query_factory=lambda: db.session().query(models.SqlaTable),
+            allow_blank=True,
+            widget=Select2Widget(extra_classes='readonly'),
+        ),
+    }
+
+    edit_form_extra_fields = add_form_extra_fields
+
 
 appbuilder.add_view_no_menu(TableColumnInlineView)
 
@@ -153,6 +166,17 @@ class SqlMetricInlineView(CompactCRUDMixin, SupersetModelView):  # noqa
         'warning_text': _('Warning Message'),
     }
 
+    add_form_extra_fields = {
+        'table': QuerySelectField(
+            'Table',
+            query_factory=lambda: db.session().query(models.SqlaTable),
+            allow_blank=True,
+            widget=Select2Widget(extra_classes='readonly'),
+        ),
+    }
+
+    edit_form_extra_fields = add_form_extra_fields
+
     def post_add(self, metric):
         if metric.is_restricted:
             security_manager.add_permission_view_menu('metric_access', metric.get_perm())
@@ -260,6 +284,14 @@ class TableModelView(DatasourceModelView, DeleteMixin, YamlExportMixin):
 # noqa
         'modified': _('Modified'),
     }
 
+    edit_form_extra_fields = {
+        'database': QuerySelectField(
+            'Database',
+            query_factory=lambda: db.session().query(models.Database),
+            widget=Select2Widget(extra_classes='readonly'),
+        ),
+    }
+
     def pre_add(self, table):
         with db.session.no_autoflush:
             table_query = db.session.query(models.SqlaTable).filter(


Mime
View raw message