Simulate graph states in the browser
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

37 rindas
1.0KB

  1. from flask import Flask, request, redirect, url_for, make_response, render_template, Markup, send_from_directory, send_file
  2. from flask_redis import FlaskRedis
  3. import json, abp, markdown
  4. app = Flask(__name__)
  5. redis = FlaskRedis(app)
  6. @app.route("/")
  7. def index():
  8. return render_template("index.html")
  9. @app.route("/graph", methods=["GET", "POST"])
  10. def graph():
  11. if request.method == 'POST':
  12. # Convert the data to a graph state
  13. g = abp.GraphState()
  14. g.from_json(json.loads(request.data))
  15. # Convert it back to JSON just for fun
  16. data = json.dumps(g.to_json(stringify=True))
  17. # Insert into the database
  18. redis.execute_command("SET", "graph", data)
  19. # Return success
  20. return "Posted {} bytes OK".format(len(data))
  21. else:
  22. # Get from the database
  23. return redis.get("graph")
  24. @app.route("/doc")
  25. def doc():
  26. body = Markup(markdown.markdown(render_template("doc.md"), extensions=["markdown.extensions.codehilite"]))
  27. return render_template("boilerplate.html", body=body)