Merge pull request #27 from mistercrunch/dash

More refactor and bugfixes
This commit is contained in:
Maxime Beauchemin 2015-09-18 15:30:53 -07:00
commit 6f1fa5152a
3 changed files with 28 additions and 45 deletions

View File

@ -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 '<a href="{url}">{self.table_name}</a>'.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 '<a href="{url}">{self.datasource_name}</a>'.format(**locals())
def get_metric_obj(self, metric_name):

View File

@ -201,23 +201,32 @@ def ping():
class Panoramix(BaseView):
@has_access
@expose("/table/<table_id>/")
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/<datasource_type>/<datasource_id>/")
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/<datasource_name>/")
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):

View File

@ -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)