Skip to content

Commit

Permalink
moved get querystring logic into its own func
Browse files Browse the repository at this point in the history
  • Loading branch information
Mogball committed Sep 22, 2017
1 parent b264960 commit 7fa4137
Showing 1 changed file with 16 additions and 25 deletions.
41 changes: 16 additions & 25 deletions superset/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,20 @@ def slice(self, slice_id):
endpoint += '&standalone=true'
return redirect(endpoint)

def get_query_string_response(self, viz_obj):
try:
query_obj = viz_obj.query_obj()
query = viz_obj.datasource.get_query_str(query_obj)
except Exception as e:
return json_error_response(e)
return Response(
json.dumps({
'query': query,
'language': viz_obj.datasource.query_language,
}),
status=200,
mimetype="application/json")

@log_this
@has_access_api
@expose("/explore_json/<datasource_type>/<datasource_id>/")
Expand All @@ -970,18 +984,7 @@ def explore_json(self, datasource_type, datasource_id):
mimetype="application/csv")

if request.args.get("query") == "true":
try:
query_obj = viz_obj.query_obj()
query = viz_obj.datasource.get_query_str(query_obj)
except Exception as e:
return json_error_response(e)
return Response(
json.dumps({
'query': query,
'language': viz_obj.datasource.query_language,
}),
status=200,
mimetype="application/json")
return self.get_query_string_response(viz_obj)

payload = {}
try:
Expand Down Expand Up @@ -2324,19 +2327,7 @@ def sliceQuery(self, slice_id):
viz_obj = self.get_viz(slice_id)
if not self.datasource_access(viz_obj.datasource):
return json_error_response(DATASOURCE_ACCESS_ERR, status=401)
try:
query_obj = viz_obj.query_obj()
query = viz_obj.datasource.get_query_str(query_obj)
except Exception as e:
return json_error_response(e)
return Response(
json.dumps({
'query': query,
'language': viz_obj.datasource.query_language,
}),
status=200,
mimetype="application/json"
)
return self.get_query_string_response(viz_obj)

appbuilder.add_view_no_menu(Superset)

Expand Down

0 comments on commit 7fa4137

Please sign in to comment.