mirror of https://github.com/apache/superset.git
expose /slice/<slice_id>/ endpoint to redirect to a slice's url (#633)
* expose /slice/<slice_id>/ endpoint to redirect to a slice's url * remove residual print statement * add unit test for caravel/slices/id endpoint
This commit is contained in:
parent
deb197a1d8
commit
668ede1133
|
@ -953,6 +953,19 @@ class Caravel(BaseView):
|
||||||
json.dumps({'count': count}),
|
json.dumps({'count': count}),
|
||||||
mimetype="application/json")
|
mimetype="application/json")
|
||||||
|
|
||||||
|
@has_access
|
||||||
|
@expose("/slice/<slice_id>/")
|
||||||
|
def slice(self, slice_id):
|
||||||
|
"""Redirects a request for a slice id to its corresponding URL"""
|
||||||
|
session = db.session()
|
||||||
|
qry = session.query(models.Slice).filter_by(id=int(slice_id))
|
||||||
|
slc = qry.first()
|
||||||
|
if slc:
|
||||||
|
return redirect(slc.slice_url)
|
||||||
|
else:
|
||||||
|
flash("The specified slice could not be found", "danger")
|
||||||
|
return redirect('/slicemodelview/list/')
|
||||||
|
|
||||||
@has_access
|
@has_access
|
||||||
@expose("/dashboard/<dashboard_id>/")
|
@expose("/dashboard/<dashboard_id>/")
|
||||||
def dashboard(self, dashboard_id):
|
def dashboard(self, dashboard_id):
|
||||||
|
|
|
@ -140,13 +140,14 @@ class CoreTests(CaravelTestCase):
|
||||||
assert 'Energy' in resp.data.decode('utf-8')
|
assert 'Energy' in resp.data.decode('utf-8')
|
||||||
|
|
||||||
def test_slices(self):
|
def test_slices(self):
|
||||||
# Testing by running all the examples
|
# Testing by hitting the two supported end points for all slices
|
||||||
self.login(username='admin')
|
self.login(username='admin')
|
||||||
Slc = models.Slice
|
Slc = models.Slice
|
||||||
urls = []
|
urls = []
|
||||||
for slc in db.session.query(Slc).all():
|
for slc in db.session.query(Slc).all():
|
||||||
urls += [
|
urls += [
|
||||||
(slc.slice_name, 'slice_url', slc.slice_url),
|
(slc.slice_name, 'slice_url', slc.slice_url),
|
||||||
|
(slc.slice_name, 'slice_id_endpoint', '/caravel/slices/{}'.format(slc.id)),
|
||||||
(slc.slice_name, 'json_endpoint', slc.viz.json_endpoint),
|
(slc.slice_name, 'json_endpoint', slc.viz.json_endpoint),
|
||||||
(slc.slice_name, 'csv_endpoint', slc.viz.csv_endpoint),
|
(slc.slice_name, 'csv_endpoint', slc.viz.csv_endpoint),
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in New Issue