Simulate graph states in the browser
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

33 lignes
811B

  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
  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(page):
  11. if request.method == 'POST':
  12. # Convert the data to a graph state
  13. g = abp.GraphState()
  14. g.from_json(json.loads(data))
  15. # Convert it back to JSON
  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 "OK"
  21. else:
  22. # Get from the database
  23. return redis.get("graph")