topic_tool_setting.py 3.2 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. do_add_thread(
  34. topic_num,
  35. t_state + (' (Agree)' if agree_d != '' else '') + (('[br][br]Why : ' + why_d) if why_d else ''),
  36. '1'
  37. )
  38. do_reload_recent_thread(
  39. topic_num,
  40. time
  41. )
  42. return redirect('/thread/' + topic_num)
  43. else:
  44. stop_d_list = ''
  45. agree_check = ''
  46. for_list = [
  47. ['O', 'Close'],
  48. ['S', 'Stop'],
  49. ['', 'Normal']
  50. ]
  51. for i in for_list:
  52. if rd_d and rd_d[0][0] == i[0]:
  53. stop_d_list = '<option value="' + i[0] + '">' + i[1] + '</option>' + stop_d_list
  54. else:
  55. stop_d_list += '<option value="' + i[0] + '">' + i[1] + '</option>'
  56. agree_check = 'checked="checked"' if rd_d[0][1] == 'O' else ''
  57. return easy_minify(flask.render_template(skin_check(),
  58. imp = [load_lang('topic_setting'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
  59. data = '''
  60. <form method="post">
  61. <select name="stop_d">
  62. ''' + stop_d_list + '''
  63. </select>
  64. <hr class=\"main_hr\">
  65. <input type="checkbox" name="agree" value="O" ''' + agree_check + '''> Agree
  66. <hr class=\"main_hr\">
  67. <input placeholder="''' + load_lang('why') + ''' (''' + load_lang('markup_enabled') + ''')" name="why" type="text">
  68. <hr class=\"main_hr\">
  69. <button type="submit">''' + load_lang('save') + '''</button>
  70. </form>
  71. ''',
  72. menu = [['thread/' + topic_num + '/tool', load_lang('return')]]
  73. ))