diff --git a/app.py b/app.py index a76ba3c..677f215 100644 --- a/app.py +++ b/app.py @@ -1,4 +1,4 @@ -from flask import Flask, request, redirect, url_for, make_response, render_template, Markup, send_from_directory, send_file +from flask import Flask, request, redirect, url_for, make_response, render_template, Markup, send_from_directory, send_file, jsonify, Response from flask_redis import FlaskRedis import json, abp, markdown from pprint import pprint @@ -35,12 +35,12 @@ def graph(uuid): return "Posted {} bytes OK".format(len(data)) elif redis.exists(uuid): - return redis.get(uuid) + return jsonify(json.loads(redis.get(uuid))) else: g = abp.GraphState() - data = json.dumps(g.to_json(stringify=True)) - redis.setex(uuid, DAY, data) - return data + data = g.to_json(stringify=True) + redis.setex(uuid, DAY, json.dumps(data)) + return jsonify(data) @app.route("//edit", methods=["POST"]) def edit(uuid): @@ -85,3 +85,10 @@ def doc(): body = Markup(markdown.markdown(render_template("doc.md"), extensions=["markdown.extensions.codehilite"])) return render_template("boilerplate.html", body=body) + +@app.route("//download") +def download(uuid): + return Response(redis.get(uuid), + mimetype='application/json', + headers={'Content-Disposition':'attachment;filename=graph.json'}) + diff --git a/templates/index.html b/templates/index.html index a44a917..4ebdd57 100644 --- a/templates/index.html +++ b/templates/index.html @@ -45,6 +45,7 @@