2
0

api_w.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. 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. return flask.jsonify({ "title" : name, "data" : g_data[0], "js_data" : g_data[1] })
  15. else:
  16. curs.execute(db_change("select data from data where title = ?"), [name])
  17. data = curs.fetchall()
  18. if data:
  19. if flask.request.args.get('include', 'include_1'):
  20. json_data = data[0][0]
  21. get_all_change_1 = [('@' + i[0] + '@', i[1]) for i in re.findall(r'@([^=]+)=([^@]+)@', json_data)]
  22. json_data = re.sub(r'@(?P<in>[^=]+)=([^@]+)@', '@\g<in>@', json_data)
  23. get_all_change_2 = re.findall(r'(@(?:[^@]*)@),([^,]*),', flask.request.args.get('change', '')) + get_all_change_1
  24. for i in get_all_change_2:
  25. json_data = json_data.replace(
  26. i[0].replace('<amp>', '&'),
  27. i[1].replace('<amp>', '&').replace('<comma>', ',')
  28. )
  29. g_data = render_set(title = name, data = json_data, num = 2, include = flask.request.args.get('include', 'include_1'))
  30. else:
  31. json_data = g_data[0]
  32. g_data = render_set(title = name, data = json_data, num = 2)
  33. return flask.jsonify({ "title" : name, "data" : g_data[0], "js_data" : g_data[1] })
  34. else:
  35. return flask.jsonify({})
  36. else:
  37. return flask.jsonify({})