Redirect to explore view when saving a table (#2479)

This commit is contained in:
Maxime Beauchemin 2017-03-31 08:26:49 -07:00 committed by GitHub
parent 66cc546a30
commit b81968dc20
1 changed files with 23 additions and 9 deletions

View File

@ -1,7 +1,10 @@
"""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
@ -9,6 +12,7 @@ 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,
@ -198,20 +202,30 @@ class TableModelView(SupersetModelView, DeleteMixin): # noqa
"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,