mirror of
https://github.com/apache/superset.git
synced 2024-09-12 08:39:45 -04:00
Error handling and table links
This commit is contained in:
parent
50d7d0fb5b
commit
9c47415d62
@ -269,9 +269,13 @@ class Database(Model, AuditMixinNullable):
|
||||
conn.password = self.password
|
||||
return str(conn)
|
||||
|
||||
@property
|
||||
def sql_url(self):
|
||||
return '/panoramix/sql/{}/'.format(self.id)
|
||||
|
||||
@property
|
||||
def sql_link(self):
|
||||
return '<a href="/panoramix/sql/{}/">SQL</a>'.format(self.id)
|
||||
return '<a href="{}">SQL</a>'.format(self.sql_url)
|
||||
|
||||
|
||||
class SqlaTable(Model, Queryable, AuditMixinNullable):
|
||||
@ -449,6 +453,14 @@ class SqlaTable(Model, Queryable, AuditMixinNullable):
|
||||
return QueryResult(
|
||||
df=df, duration=datetime.now() - qry_start_dttm, query=sql)
|
||||
|
||||
@property
|
||||
def sql_url(self):
|
||||
return self.database.sql_url + "?table_id=" + str(self.id)
|
||||
|
||||
@property
|
||||
def sql_link(self):
|
||||
return '<a href="{}">SQL</a>'.format(self.sql_url)
|
||||
|
||||
def query(
|
||||
self, groupby, metrics,
|
||||
granularity,
|
||||
|
@ -468,6 +468,7 @@ var px = (function() {
|
||||
editor.setValue(msg);
|
||||
});
|
||||
});
|
||||
$("#select_star").click();
|
||||
$("#run").click(function() {
|
||||
$('#results').hide(0);
|
||||
$('#loading').show(0);
|
||||
|
@ -18,6 +18,10 @@
|
||||
border-radius: 5px;
|
||||
background-color: #EEE;
|
||||
}
|
||||
div.alert {
|
||||
padding: 5px;
|
||||
margin: 0px;
|
||||
}
|
||||
.metadata {
|
||||
overflow: auto;
|
||||
width: 300px;
|
||||
@ -36,6 +40,7 @@
|
||||
#results {
|
||||
overflow: auto;
|
||||
font-size: 12px;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
#results table tbody tr td{
|
||||
padding: 2px 4px;
|
||||
@ -56,7 +61,10 @@
|
||||
<div class="col-xs-5 fillheight">
|
||||
<select id="dbtable">
|
||||
{% for table in db.tables %}
|
||||
<option value="{{ table.id }}">{{ table }}</option>
|
||||
<option value="{{ table.id }}"
|
||||
{{ "selected" if table.id|string == table_id }}>
|
||||
{{ table }}
|
||||
</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<button class="btn btn-default" id="select_star">SELECT *</button>
|
||||
|
@ -146,7 +146,8 @@ appbuilder.add_view(
|
||||
|
||||
class TableView(PanoramixModelView, DeleteMixin):
|
||||
datamodel = SQLAInterface(models.SqlaTable)
|
||||
list_columns = ['table_link', 'database', 'changed_by', 'changed_on_']
|
||||
list_columns = [
|
||||
'table_link', 'database', 'sql_link', 'changed_by_', 'changed_on_']
|
||||
add_columns = ['table_name', 'database', 'default_endpoint', 'offset']
|
||||
edit_columns = [
|
||||
'table_name', 'is_featured', 'database', 'description', 'owner',
|
||||
@ -278,7 +279,7 @@ class DatasourceModelView(PanoramixModelView, DeleteMixin):
|
||||
list_columns = [
|
||||
'datasource_link', 'cluster', 'owner',
|
||||
'created_by', 'created_on',
|
||||
'changed_by', 'changed_on',
|
||||
'changed_by_', 'changed_on',
|
||||
'offset']
|
||||
related_views = [ColumnInlineView, MetricInlineView]
|
||||
edit_columns = [
|
||||
@ -561,6 +562,7 @@ class Panoramix(BaseView):
|
||||
return self.render_template(
|
||||
"panoramix/sql.html",
|
||||
database_id=database_id,
|
||||
table_id=request.args.get('table_id'),
|
||||
db=mydb)
|
||||
|
||||
@has_access
|
||||
@ -579,7 +581,7 @@ class Panoramix(BaseView):
|
||||
t = db.session.query(models.SqlaTable).filter_by(id=table_id).first()
|
||||
fields = ", ".join(
|
||||
[c.column_name for c in t.columns if not c.expression] or "*")
|
||||
s = "SELECT\n{fields}\nFROM {t.table_name}\nLIMIT 1000".format(**locals())
|
||||
s = "SELECT\n{fields}\nFROM {t.table_name}".format(**locals())
|
||||
return self.render_template(
|
||||
"panoramix/ajah.html",
|
||||
content=s)
|
||||
@ -608,12 +610,18 @@ class Panoramix(BaseView):
|
||||
.limit(limit)
|
||||
)
|
||||
sql= str(qry.compile(eng, compile_kwargs={"literal_binds": True}))
|
||||
df = read_sql_query(sql=sql, con=eng)
|
||||
content = df.to_html(
|
||||
index=False,
|
||||
classes=(
|
||||
"dataframe table table-striped table-bordered "
|
||||
"table-condensed sql_results"))
|
||||
try:
|
||||
df = read_sql_query(sql=sql, con=eng)
|
||||
content = df.to_html(
|
||||
index=False,
|
||||
classes=(
|
||||
"dataframe table table-striped table-bordered "
|
||||
"table-condensed sql_results"))
|
||||
except Exception as e:
|
||||
content = (
|
||||
'<div class="alert alert-danger">'
|
||||
"{}</div>"
|
||||
).format(e.message)
|
||||
session.commit()
|
||||
return content
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user