api_w.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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(db_change("select title from data where title = ?"), [name])
  6. if curs.fetchall():
  7. return flask.jsonify({ "exist" : "1" })
  8. else:
  9. if acl_check(name, 'render') != 1:
  10. if flask.request.method == 'POST':
  11. g_data = flask.request.form.get('data', '')
  12. g_data = render_set(title = name, data = g_data, num = 2)
  13. return flask.jsonify({ "title" : name, "data" : g_data[0], "js_data" : g_data[1] })
  14. else:
  15. curs.execute(db_change("select data from data where title = ?"), [name])
  16. data = curs.fetchall()
  17. if data:
  18. json_data = data[0][0]
  19. include_data = flask.request.args.get('include', None)
  20. if include_data:
  21. get_all_change_1 = []
  22. find_replace_moment = re.findall(r'(@([^=@]+)=([^=@]+)@|@([^=@]+)@)', json_data)
  23. for i in find_replace_moment:
  24. if i[1] != '':
  25. get_all_change_1 += [['@' + i[1] + '@', i[2]]]
  26. json_data = json_data.replace(i[0], '@' + i[1] + '@', 1)
  27. else:
  28. json_data = json_data.replace(i[0], '@' + i[3] + '@', 1)
  29. get_all_change_2 = re.findall(r'(@(?:[^@]*)@),([^,]*),', flask.request.args.get('change', '')) + get_all_change_1
  30. for i in get_all_change_2:
  31. json_data = json_data.replace(
  32. i[0].replace('<amp>', '&'),
  33. i[1].replace('<amp>', '&').replace('<comma>', ','),
  34. 1
  35. )
  36. g_data = render_set(title = name, data = json_data, num = 2, include = include_data)
  37. return flask.jsonify({ "title" : name, "data" : g_data[0], "js_data" : g_data[1] })
  38. return flask.jsonify({})