2
0

topic_tool_setting.py 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. from .tool.func import *
  2. def topic_tool_setting(topic_num = 1):
  3. with get_db_connect() as conn:
  4. curs = conn.cursor()
  5. if admin_check(3) != 1:
  6. return re_error('/error/3')
  7. ip = ip_check()
  8. time = get_time()
  9. topic_num = str(topic_num)
  10. curs.execute(db_change("select stop, agree from rd where code = ?"), [topic_num])
  11. rd_d = curs.fetchall()
  12. if not rd_d:
  13. return redirect('/')
  14. if flask.request.method == 'POST':
  15. admin_check(3, 'change_topic_set (code ' + topic_num + ')')
  16. curs.execute(db_change("select id from topic where code = ? order by id + 0 desc limit 1"), [topic_num])
  17. topic_check = curs.fetchall()
  18. if topic_check:
  19. stop_d = flask.request.form.get('stop_d', '')
  20. why_d = flask.request.form.get('why', '')
  21. agree_d = flask.request.form.get('agree', '')
  22. curs.execute(db_change("update rd set stop = ?, agree = ? where code = ?"), [
  23. stop_d,
  24. agree_d,
  25. topic_num
  26. ])
  27. if stop_d == 'S':
  28. t_state = 'Stop'
  29. elif stop_d == 'O':
  30. t_state = 'Close'
  31. else:
  32. t_state = 'Normal'
  33. curs.execute(db_change("insert into topic (id, data, date, ip, top, code) values (?, ?, ?, ?, '1', ?)"), [
  34. str(int(topic_check[0][0]) + 1),
  35. t_state + (' (Agree)' if agree_d != '' else '') + (('[br][br]Why : ' + why_d) if why_d else ''),
  36. time,
  37. ip,
  38. topic_num
  39. ])
  40. rd_plus(topic_num, time)
  41. return redirect('/thread/' + topic_num)
  42. else:
  43. stop_d_list = ''
  44. agree_check = ''
  45. for_list = [
  46. ['O', 'Close'],
  47. ['S', 'Stop'],
  48. ['', 'Normal']
  49. ]
  50. for i in for_list:
  51. if rd_d and rd_d[0][0] == i[0]:
  52. stop_d_list = '<option value="' + i[0] + '">' + i[1] + '</option>' + stop_d_list
  53. else:
  54. stop_d_list += '<option value="' + i[0] + '">' + i[1] + '</option>'
  55. agree_check = 'checked="checked"' if rd_d[0][1] == 'O' else ''
  56. return easy_minify(flask.render_template(skin_check(),
  57. imp = [load_lang('topic_setting'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
  58. data = '''
  59. <form method="post">
  60. <select name="stop_d">
  61. ''' + stop_d_list + '''
  62. </select>
  63. <hr class=\"main_hr\">
  64. <input type="checkbox" name="agree" value="O" ''' + agree_check + '''> Agree
  65. <hr class=\"main_hr\">
  66. <input placeholder="''' + load_lang('why') + ''' (''' + load_lang('markup_enabled') + ''')" name="why" type="text">
  67. <hr class=\"main_hr\">
  68. <button type="submit">''' + load_lang('save') + '''</button>
  69. </form>
  70. ''',
  71. menu = [['thread/' + topic_num + '/tool', load_lang('return')]]
  72. ))