api_w.py 1.2 KB

123456789101112131415161718192021222324252627282930
  1. from .tool.func import *
  2. def api_w_2(conn, name):
  3. curs = conn.cursor()
  4. if flask.request.args.get('exist', None):
  5. curs.execute("select title from data where title = ?", [name])
  6. if curs.fetchall():
  7. return flask.jsonify({ "exist" : "1" })
  8. else:
  9. return flask.jsonify({})
  10. else:
  11. if acl_check(name, 'render') != 1:
  12. if flask.request.method == 'POST':
  13. g_data = render_set(title = name, data = flask.request.form.get('data', ''), num = 2)
  14. json_data = { "title" : name, "data" : g_data[0], "js_data" : g_data[1] }
  15. return flask.jsonify(json_data)
  16. else:
  17. curs.execute("select data from data where title = ?", [name])
  18. data = curs.fetchall()
  19. if data:
  20. g_data = render_set(title = name, data = data[0][0], num = 2)
  21. json_data = { "title" : name, "data" : g_data[0], "js_data" : g_data[1] }
  22. return flask.jsonify(json_data)
  23. else:
  24. return flask.jsonify({})
  25. else:
  26. return flask.jsonify({})