api_w.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. include_re = re.compile(r'\[include\(((?:(?!\)\]).)+)\)\]', re.I)
  21. category_re = re.compile(r'\[\[(?:(?:category|분류):(?:(?!\[\[|\]\]).)+)\]\]', re.I)
  22. json_data = include_re.sub('', data[0][0])
  23. json_data = category_re.sub('', json_data)
  24. get_all_change_1 = [('@' + i[0] + '@', i[1]) for i in re.findall(r'@([^=]+)=([^@]+)@', json_data)]
  25. json_data = re.sub(r'@(?P<in>[^=]+)=([^@]+)@', '@\g<in>@', json_data)
  26. get_all_change_2 = re.findall(r'(@(?:[^@]*)@),([^,]*),', flask.request.args.get('change', '')) + get_all_change_1
  27. for i in get_all_change_2:
  28. json_data = json_data.replace(
  29. i[0].replace('<amp>', '&'),
  30. i[1].replace('<amp>', '&').replace('<comma>', ',')
  31. )
  32. g_data = render_set(title = name, data = json_data, num = 2, include = flask.request.args.get('include', 'include_1'))
  33. else:
  34. json_data = g_data[0]
  35. g_data = render_set(title = name, data = json_data, num = 2)
  36. return flask.jsonify({ "title" : name, "data" : g_data[0], "js_data" : g_data[1] })
  37. else:
  38. return flask.jsonify({})
  39. else:
  40. return flask.jsonify({})