edit_delete.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. from .tool.func import *
  2. def edit_delete_2(conn, name, app_var):
  3. curs = conn.cursor()
  4. ip = ip_check()
  5. if acl_check(name) == 1:
  6. return re_error('/ban')
  7. if flask.request.method == 'POST':
  8. if captcha_post(flask.request.form.get('g-recaptcha-response', '')) == 1:
  9. return re_error('/error/13')
  10. else:
  11. captcha_post('', 0)
  12. if slow_edit_check() == 1:
  13. return re_error('/error/24')
  14. curs.execute(db_change("select data from data where title = ?"), [name])
  15. data = curs.fetchall()
  16. if data:
  17. today = get_time()
  18. leng = '-' + str(len(data[0][0]))
  19. history_plus(
  20. name,
  21. '',
  22. today,
  23. ip,
  24. flask.request.form.get('send', ''),
  25. leng,
  26. 'delete'
  27. )
  28. curs.execute(db_change("select title, link from back where title = ? and not type = 'cat' and not type = 'no'"), [name])
  29. for data in curs.fetchall():
  30. curs.execute(db_change("insert into back (title, link, type) values (?, ?, 'no')"), [data[0], data[1]])
  31. curs.execute(db_change("delete from back where link = ?"), [name])
  32. curs.execute(db_change("delete from data where title = ?"), [name])
  33. conn.commit()
  34. file_check = re.search('^file:(.+)\.(.+)$', name)
  35. if file_check:
  36. file_check = file_check.groups()
  37. os.remove(os.path.join(
  38. app_var['path_data_image'],
  39. sha224_replace(file_check[0], 'utf-8') + '.' + file_check[1]
  40. ))
  41. curs.execute(db_change('select data from other where name = "count_all_title"'))
  42. curs.execute(db_change("update other set data = ? where name = 'count_all_title'"), [str(int(curs.fetchall()[0][0]) - 1)])
  43. return redirect('/w/' + url_pas(name))
  44. else:
  45. curs.execute(db_change("select title from data where title = ?"), [name])
  46. if not curs.fetchall():
  47. return redirect('/w/' + url_pas(name))
  48. return easy_minify(flask.render_template(skin_check(),
  49. imp = [name, wiki_set(), custom(), other2([' (' + load_lang('delete') + ')', 0])],
  50. data = '''
  51. <form method="post">
  52. ''' + ip_warring() + '''
  53. <input placeholder="''' + load_lang('why') + '''" name="send" type="text">
  54. <hr class=\"main_hr\">
  55. ''' + captcha_get() + '''
  56. <button type="submit">''' + load_lang('delete') + '''</button>
  57. </form>
  58. ''',
  59. menu = [['w/' + url_pas(name), load_lang('return')]]
  60. ))