bbs_w_delete.py 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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('/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() != 1:
  14. return redirect('/bbs/w/' + 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('/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('/bbs/w/' + 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. print(set_id, set_code)
  32. curs.execute(db_change("update bbs_data set set_data = '' where set_code = ? and set_id = ?"), [set_code, set_id])
  33. return redirect('/bbs/w/' + bbs_num_str + '/' + post_num_str)
  34. else:
  35. sub = '(' + bbs_name + ')'
  36. sub += ' (' + post_num_str + ')'
  37. name = load_lang('bbs_post_delete')
  38. if comment_num == '':
  39. name = load_lang('bbs_comment_delete')
  40. else:
  41. sub += ' (' + comment_num + ')'
  42. return easy_minify(flask.render_template(skin_check(),
  43. imp = [name, wiki_set(), wiki_custom(), wiki_css([sub, 0])],
  44. data = render_simple_set('''
  45. <form method="post">
  46. <span>''' + load_lang('delete_warning') + '''</span>
  47. <hr class="main_hr">
  48. <button type="submit">''' + load_lang('delete') + '''</button>
  49. </form>
  50. '''),
  51. menu = [['bbs/w/' + bbs_num_str + '/' + post_num_str, load_lang('return')]]
  52. ))