diff --git a/panoramix/models.py b/panoramix/models.py
index 93610b75f..7ef896f07 100644
--- a/panoramix/models.py
+++ b/panoramix/models.py
@@ -71,7 +71,7 @@ class Slice(Model, AuditMixin):
d = json.loads(self.params)
from werkzeug.urls import Href
href = Href(
- "/panoramix/{self.datasource_type}/"
+ "/panoramix/datasource/{self.datasource_type}/"
"{self.datasource_id}/".format(self=self))
return href(d)
@@ -191,7 +191,7 @@ class Table(Model, Queryable, AuditMixin):
@property
def table_link(self):
- url = "/panoramix/table/{}/".format(self.id)
+ url = "/panoramix/datasource/{self.type}/{self.id}/".format(self=self)
return '{self.table_name}'.format(**locals())
@property
@@ -579,7 +579,9 @@ class Datasource(Model, AuditMixin, Queryable):
@property
def datasource_link(self):
- url = "/panoramix/datasource/{}/".format(self.datasource_name)
+ url = (
+ "/panoramix/datasource/"
+ "{self.type}/{self.id}/").format(self=self)
return '{self.datasource_name}'.format(**locals())
def get_metric_obj(self, metric_name):
diff --git a/panoramix/views.py b/panoramix/views.py
index 8ff805fd5..e16c512b9 100644
--- a/panoramix/views.py
+++ b/panoramix/views.py
@@ -201,23 +201,32 @@ def ping():
class Panoramix(BaseView):
@has_access
- @expose("/table//")
- def table(self, table_id):
- table = (
- db.session
- .query(models.Table)
- .filter_by(id=table_id)
- .first()
- )
- if not table:
- flash("The table seem to have been deleted", "alert")
+ @expose("/datasource///")
+ def datasource(self, datasource_type, datasource_id):
+ if datasource_type == "table":
+ datasource = (
+ db.session
+ .query(models.Table)
+ .filter_by(id=datasource_id)
+ .first()
+ )
+ else:
+ datasource = (
+ db.session
+ .query(models.Datasource)
+ .filter_by(id=datasource_id)
+ .first()
+ )
+
+ if not datasource:
+ flash("The datasource seem to have been deleted", "alert")
viz_type = request.args.get("viz_type")
- if not viz_type and table.default_endpoint:
- return redirect(table.default_endpoint)
+ if not viz_type and datasource.default_endpoint:
+ return redirect(datasource.default_endpoint)
if not viz_type:
viz_type = "table"
obj = viz.viz_types[viz_type](
- table,
+ datasource,
form_data=request.args)
if request.args.get("json") == "true":
try:
@@ -251,33 +260,6 @@ class Panoramix(BaseView):
session.close()
return "SUCCESS"
- @has_access
- @expose("/datasource//")
- def datasource(self, datasource_name):
- viz_type = request.args.get("viz_type")
- datasource = (
- db.session
- .query(models.Datasource)
- .filter_by(datasource_name=datasource_name)
- .first()
- )
- if not viz_type and datasource.default_endpoint:
- return redirect(datasource.default_endpoint)
- if not viz_type:
- viz_type = "table"
- obj = viz.viz_types[viz_type](
- datasource,
- form_data=request.args)
- if request.args.get("json"):
- return Response(
- json.dumps(obj.get_query(), indent=4),
- status=200,
- mimetype="application/json")
- if not hasattr(obj, 'df') or obj.df is None or obj.df.empty:
- return obj.render_no_data()
-
- return obj.check_and_render()
-
@has_access
@expose("/save/")
def save(self):
diff --git a/panoramix/viz.py b/panoramix/viz.py
index ebf0cf9c4..657a7c689 100644
--- a/panoramix/viz.py
+++ b/panoramix/viz.py
@@ -48,9 +48,8 @@ class BaseViz(object):
def get_url(self, **kwargs):
d = self.args.copy()
d.update(kwargs)
- href = Href('/panoramix/table/2/')
href = Href(
- '/panoramix/{self.datasource.type}/'
+ '/panoramix/datasource/{self.datasource.type}/'
'{self.datasource.id}/'.format(**locals()))
return href(d)