topic_acl.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. from .tool.func import *
  2. def topic_acl_2(conn, topic_num):
  3. curs = conn.cursor()
  4. if admin_check(3) != 1:
  5. return re_error('/error/3')
  6. ip = ip_check()
  7. time = get_time()
  8. topic_num = str(topic_num)
  9. curs.execute(db_change("select title, sub from rd where code = ?"), [topic_num])
  10. rd_d = curs.fetchall()
  11. if not rd_d:
  12. return redirect('/')
  13. if flask.request.method == 'POST':
  14. admin_check(3, 'topic_acl_set (code ' + topic_num + ')')
  15. curs.execute(db_change("select id from topic where code = ? order by id + 0 desc limit 1"), [topic_num])
  16. topic_check = curs.fetchall()
  17. if topic_check:
  18. acl_data = flask.request.form.get('acl', '')
  19. curs.execute(db_change("update rd set acl = ? where code = ?"), [
  20. acl_data,
  21. topic_num
  22. ])
  23. curs.execute(db_change("insert into topic (id, data, date, ip, top, code) values (?, ?, ?, ?, '1', ?)"), [
  24. str(int(topic_check[0][0]) + 1),
  25. 'acl change ' + acl_data,
  26. time,
  27. ip,
  28. topic_num
  29. ])
  30. rd_plus(topic_num, time)
  31. return redirect('/thread/' + topic_num)
  32. else:
  33. acl_list = get_acl_list()
  34. acl_html_list = ''
  35. curs.execute(db_change("select acl from rd where code = ?"), [topic_num])
  36. topic_acl_get = curs.fetchall()
  37. for data_list in acl_list:
  38. if topic_acl_get and topic_acl_get[0][0] == data_list:
  39. check = 'selected="selected"'
  40. else:
  41. check = ''
  42. acl_html_list += '<option value="' + data_list + '" ' + check + '>' + (data_list if data_list != '' else 'normal') + '</option>'
  43. return easy_minify(flask.render_template(skin_check(),
  44. imp = [load_lang('topic_acl_setting'), wiki_set(), custom(), other2([0, 0])],
  45. data = '''
  46. <form method="post">
  47. <a href="/acl/TEST#exp">(''' + load_lang('reference') + ''')</a>
  48. <hr>
  49. <select name="acl">
  50. ''' + acl_html_list + '''
  51. </select>
  52. <hr class=\"main_hr\">
  53. <button type="submit">''' + load_lang('save') + '''</button>
  54. </form>
  55. ''',
  56. menu = [['thread/' + topic_num + '/tool', load_lang('return')]]
  57. ))