Skip to content
Snippets Groups Projects
Verified Commit ac12d2d4 authored by David Hoese's avatar David Hoese
Browse files

Fix status API to return HTML when no information is found

parent 23259af5
No related branches found
No related tags found
No related merge requests found
......@@ -112,6 +112,22 @@ def status_index():
return render_template('status_index.html')
def _status_dict_to_html(response):
items = "<br>\n".join("{}: {}".format(k, v) for k, v in sorted(response.items()))
return """<html>
<body>
{}
</body>
</html>""".format(items)
def _status_render(response, fmt):
if fmt == 'json':
return jsonify(response)
else:
return _status_dict_to_html(response)
@app.route('/api/status/<site>/<inst>.<fmt>', methods=['GET'])
@app.route('/api/status/<site>/<inst>', methods=['GET'])
@app.route('/api/status/<site>.<fmt>', methods=['GET'])
......@@ -119,6 +135,7 @@ def status_index():
def get_instrument_status(site, inst=None, fmt=None):
"""See `/api/status/` for more information."""
# defaults:
print(site, inst, fmt)
response = {
"name": site if inst is None else inst,
"short_name": "",
......@@ -160,14 +177,11 @@ def get_instrument_status(site, inst=None, fmt=None):
if json_str is None:
# exit out early, we don't know what this is
return jsonify(response)
return _status_render(response, fmt)
json_dict = builtin_json.loads(json_str)
response.update(json_dict)
if fmt == 'json':
return jsonify(response)
else:
return "<br>".join("{}: {}".format(k, v) for k, v in sorted(response.items()))
return _status_render(response, fmt)
if __name__ == '__main__':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment