Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add verbose name to db and druid cluster #2429

Merged
merged 3 commits into from
Mar 17, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 8 additions & 2 deletions superset/connectors/druid/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class DruidCluster(Model, AuditMixinNullable):
type = "druid"

id = Column(Integer, primary_key=True)
verbose_name = Column(String(250), unique=True)
# short unique name, used in permissions
cluster_name = Column(String(250), unique=True)
coordinator_host = Column(String(255))
coordinator_port = Column(Integer)
Expand All @@ -69,7 +71,7 @@ class DruidCluster(Model, AuditMixinNullable):
cache_timeout = Column(Integer)

def __repr__(self):
return self.cluster_name
return self.verbose_name if self.verbose_name else self.cluster_name

def get_pydruid_client(self):
cli = PyDruid(
Expand Down Expand Up @@ -107,7 +109,11 @@ def perm(self):

@property
def name(self):
return self.cluster_name
return self.verbose_name if self.verbose_name else self.cluster_name

@property
def unique_name(self):
return self.verbose_name if self.verbose_name else self.cluster_name


class DruidColumn(Model, BaseColumn):
Expand Down
6 changes: 3 additions & 3 deletions superset/connectors/druid/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ def post_update(self, metric):
class DruidClusterModelView(SupersetModelView, DeleteMixin): # noqa
datamodel = SQLAInterface(models.DruidCluster)
add_columns = [
'cluster_name',
'coordinator_host', 'coordinator_port', 'coordinator_endpoint',
'broker_host', 'broker_port', 'broker_endpoint', 'cache_timeout',
'verbose_name', 'coordinator_host', 'coordinator_port',
'coordinator_endpoint', 'broker_host', 'broker_port',
'broker_endpoint', 'cache_timeout', 'cluster_name',
]
edit_columns = add_columns
list_columns = ['cluster_name', 'metadata_last_refreshed']
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""Add verbose name to DruidCluster and Database

Revision ID: db527d8c4c78
Revises: b318dfe5fb6c
Create Date: 2017-03-16 18:10:57.193035

"""

# revision identifiers, used by Alembic.
revision = 'db527d8c4c78'
down_revision = 'b318dfe5fb6c'

from alembic import op
import logging
import sqlalchemy as sa


def upgrade():
op.add_column('clusters', sa.Column('verbose_name', sa.String(length=250), nullable=True))
op.add_column('dbs', sa.Column('verbose_name', sa.String(length=250), nullable=True))

try:
op.create_unique_constraint(None, 'dbs', ['verbose_name'])
op.create_unique_constraint(None, 'clusters', ['verbose_name'])
except Exception as e:
logging.exception(e)


def downgrade():
try:
op.drop_column('dbs', 'verbose_name')
op.drop_column('clusters', 'verbose_name')
except Exception as e:
logging.exception(e)

8 changes: 7 additions & 1 deletion superset/models/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,8 @@ class Database(Model, AuditMixinNullable):
type = "table"

id = Column(Integer, primary_key=True)
verbose_name = Column(String(250), unique=True)
# short unique name, used in permissions
database_name = Column(String(250), unique=True)
sqlalchemy_uri = Column(String(1024))
password = Column(EncryptedType(String(1024), config.get('SECRET_KEY')))
Expand All @@ -525,10 +527,14 @@ class Database(Model, AuditMixinNullable):
perm = Column(String(1000))

def __repr__(self):
return self.database_name
return self.verbose_name if self.verbose_name else self.database_name

@property
def name(self):
return self.verbose_name if self.verbose_name else self.database_name

@property
def unique_name(self):
return self.database_name

@property
Expand Down
4 changes: 2 additions & 2 deletions superset/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ def generate_download_headers(extension):
class DatabaseView(SupersetModelView, DeleteMixin): # noqa
datamodel = SQLAInterface(models.Database)
list_columns = [
'database_name', 'backend', 'allow_run_sync', 'allow_run_async',
'allow_dml', 'creator', 'changed_on_']
'verbose_name', 'backend', 'allow_run_sync', 'allow_run_async',
'allow_dml', 'creator', 'changed_on_', 'database_name']
add_columns = [
'database_name', 'sqlalchemy_uri', 'cache_timeout', 'extra',
'expose_in_sqllab', 'allow_run_sync', 'allow_run_async',
Expand Down