bbs_w_delete.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. from .tool.func import *
  2. from .api_bbs_w_post import api_bbs_w_post
  3. def bbs_w_delete(bbs_num = '', post_num = '', comment_num = ''):
  4. with get_db_connect() as conn:
  5. curs = conn.cursor()
  6. curs.execute(db_change('select set_data from bbs_set where set_id = ? and set_name = "bbs_name"'), [bbs_num])
  7. db_data = curs.fetchall()
  8. if not db_data:
  9. return redirect(conn, '/bbs/main')
  10. bbs_name = db_data[0][0]
  11. bbs_num_str = str(bbs_num)
  12. post_num_str = str(post_num)
  13. if admin_check(conn) != 1:
  14. return redirect(conn, '/bbs/in/' + bbs_num_str)
  15. temp_dict = json.loads(api_bbs_w_post(bbs_num_str + '-' + post_num_str).data)
  16. if not 'user_id' in temp_dict:
  17. return redirect(conn, '/bbs/main')
  18. if flask.request.method == 'POST':
  19. if comment_num == '':
  20. curs.execute(db_change('delete from bbs_data where set_code = ? and set_id = ?'), [post_num_str, bbs_num_str])
  21. curs.execute(db_change('delete from bbs_set where set_code = ? and set_id = ?'), [post_num_str, bbs_num_str])
  22. curs.execute(db_change('delete from bbs_data where set_id = ? or set_id like ?'), [bbs_num_str + '-' + post_num_str, bbs_num_str + '-' + post_num_str + '-%'])
  23. return redirect(conn, '/bbs/in/' + bbs_num_str)
  24. else:
  25. comment_num_split = comment_num.split('-')
  26. set_id = bbs_num_str + '-' + post_num_str
  27. set_id_sub = '-'.join(comment_num_split[:-1])
  28. if set_id_sub != '':
  29. set_id += '-' + set_id_sub
  30. set_code = comment_num_split[len(comment_num_split) - 1]
  31. curs.execute(db_change("update bbs_data set set_data = '' where set_code = ? and set_id = ?"), [set_code, set_id])
  32. return redirect(conn, '/bbs/w/' + bbs_num_str + '/' + post_num_str)
  33. else:
  34. sub = '(' + bbs_name + ')'
  35. sub += ' (' + post_num_str + ')'
  36. name = get_lang(conn, 'bbs_comment_delete')
  37. if comment_num == '':
  38. name = get_lang(conn, 'bbs_post_delete')
  39. else:
  40. sub += ' (' + comment_num + ')'
  41. return easy_minify(conn, flask.render_template(skin_check(conn),
  42. imp = [name, wiki_set(conn), wiki_custom(conn), wiki_css([sub, 0])],
  43. data = render_simple_set(conn, '''
  44. <form method="post">
  45. <span>''' + get_lang(conn, 'delete_warning') + '''</span>
  46. <hr class="main_hr">
  47. <button type="submit">''' + get_lang(conn, 'delete') + '''</button>
  48. </form>
  49. '''),
  50. menu = [['bbs/w/' + bbs_num_str + '/' + post_num_str, get_lang(conn, 'return')]]
  51. ))