api_w.py 1.1 KB

12345678910111213141516171819202122232425262728
  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({ "exsit" : "0" })
  10. else:
  11. if acl_check(name, 'render') != 1:
  12. if flask.request.method == 'POST':
  13. json_data = { "title" : name, "data" : render_set(title = name, data = flask.request.form.get('data', '')) }
  14. return flask.jsonify(json_data)
  15. else:
  16. curs.execute("select data from data where title = ?", [name])
  17. data = curs.fetchall()
  18. if data:
  19. json_data = { "title" : name, "data" : render_set(title = name, data = data[0][0]) }
  20. return flask.jsonify(json_data)
  21. else:
  22. return flask.jsonify({})
  23. else:
  24. return flask.jsonify({})