Skip to content

Commit

Permalink
More refactor and bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Sep 18, 2015
1 parent 16550b9 commit e5e2988
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 45 deletions.
8 changes: 5 additions & 3 deletions panoramix/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def slice_url(self):
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)

Expand Down Expand Up @@ -191,7 +191,7 @@ def name(self):

@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
Expand Down Expand Up @@ -579,7 +579,9 @@ def __repr__(self):

@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):
Expand Down
62 changes: 22 additions & 40 deletions panoramix/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -251,33 +260,6 @@ def save_dash(self, dashboard_id):
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):
Expand Down
3 changes: 1 addition & 2 deletions panoramix/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ def __init__(self, datasource, form_data):
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)

Expand Down

0 comments on commit e5e2988

Please sign in to comment.