Skip to content

Commit

Permalink
Redirect to explore view when saving a table (#2479)
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Mar 31, 2017
1 parent 66cc546 commit b81968d
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions superset/connectors/sqla/views.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
"""Views used by the SqlAlchemy connector"""
import logging

from flask import Markup, flash
from flask_appbuilder import CompactCRUDMixin
from past.builtins import basestring

from flask import Markup, flash, redirect
from flask_appbuilder import CompactCRUDMixin, expose
from flask_appbuilder.models.sqla.interface import SQLAInterface
import sqlalchemy as sa

from flask_babel import lazy_gettext as _
from flask_babel import gettext as __

from superset import appbuilder, db, utils, security, sm
from superset.utils import has_access
from superset.views.base import (
SupersetModelView, ListWidgetWithCheckboxes, DeleteMixin, DatasourceFilter,
get_datasource_exist_error_mgs,
Expand Down Expand Up @@ -198,20 +202,30 @@ def pre_add(self, table):
"database connection, schema, and "
"table name".format(table.name))

def post_add(self, table):
def post_add(self, table, flash_message=True):
table.fetch_metadata()
security.merge_perm(sm, 'datasource_access', table.get_perm())
if table.schema:
security.merge_perm(sm, 'schema_access', table.schema_perm)

flash(_(
"The table was created. As part of this two phase configuration "
"process, you should now click the edit button by "
"the new table to configure it."),
"info")
if flash_message:
flash(_(
"The table was created. "
"As part of this two phase configuration "
"process, you should now click the edit button by "
"the new table to configure it."), "info")

def post_update(self, table):
self.post_add(table)
self.post_add(table, flash_message=False)

@expose('/edit/<pk>', methods=['GET', 'POST'])
@has_access
def edit(self, pk):
"""Simple hack to redirect to explore view after saving"""
resp = super(TableModelView, self).edit(pk)
if isinstance(resp, basestring):
return resp
return redirect('/superset/explore/table/{}/'.format(pk))

appbuilder.add_view(
TableModelView,
Expand Down

0 comments on commit b81968d

Please sign in to comment.