vote_select.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. from .tool.func import *
  2. async def vote_select(num = 1):
  3. with get_db_connect() as conn:
  4. curs = conn.cursor()
  5. num = str(num)
  6. curs.execute(db_change('select name, subject, data, type from vote where id = ? and user = ""'), [num])
  7. data_list = curs.fetchall()
  8. if not data_list:
  9. return redirect(conn, '/vote')
  10. if data_list[0][3] == 'close' or data_list[0][3] == 'n_close':
  11. return redirect(conn, '/vote/end/' + num)
  12. if await acl_check('', 'vote', num) == 1:
  13. return redirect(conn, '/vote/end/' + num)
  14. curs.execute(db_change('select user from vote where id = ? and user = ?'), [num, ip_check()])
  15. if curs.fetchall():
  16. return redirect(conn, '/vote/end/' + num)
  17. curs.execute(db_change('select data from vote where id = ? and name = "end_date" and type = "option"'), [num])
  18. db_data = curs.fetchall()
  19. time_limit = ''
  20. if db_data:
  21. time_limit = db_data[0][0]
  22. time_db = db_data[0][0].split()[0]
  23. time_today = get_time().split()[0]
  24. if time_today > time_db:
  25. return redirect(conn, '/vote/end/' + num)
  26. vote_data = re.findall(r'([^\n]+)', data_list[0][2].replace('\r', ''))
  27. if flask.request.method == 'POST':
  28. try:
  29. vaild_check = int(flask.request.form.get('vote_data', '0'))
  30. except:
  31. return redirect(conn, '/vote/' + num)
  32. if len(vote_data) - 1 < vaild_check:
  33. return redirect(conn, '/vote/' + num)
  34. curs.execute(db_change("insert into vote (name, id, subject, data, user, type) values ('', ?, '', ?, ?, 'select')"), [
  35. num,
  36. str(vaild_check),
  37. ip_check()
  38. ])
  39. return redirect(conn, '/vote/end/' + num)
  40. else:
  41. data = '<h2>' + data_list[0][0] + '</h2>'
  42. data += '<b>' + data_list[0][1] + '</b><hr class="main_hr">' if data_list[0][1] != '' else ''
  43. data += '<span>~ ' + time_limit + '</span><hr class="main_hr">' if time_limit != '' else ''
  44. select_data = '<select name="vote_data">'
  45. line_num = 0
  46. for i in vote_data:
  47. select_data += '<option value="' + str(line_num) + '">' + i + '</option>'
  48. line_num += 1
  49. select_data += '</select>'
  50. data += '' + \
  51. '<form method="post">' + \
  52. select_data + \
  53. '<hr class="main_hr">' + \
  54. '<button type="submit">' + get_lang(conn, 'send') + '</buttom>' + \
  55. '</form>' + \
  56. ''
  57. return easy_minify(conn, flask.render_template(skin_check(conn),
  58. imp = [get_lang(conn, 'vote'), wiki_set(conn), await wiki_custom(conn), wiki_css(['(' + num + ')', 0])],
  59. data = data,
  60. menu = [['vote', get_lang(conn, 'return')], ['vote/end/' + num, get_lang(conn, 'result')]]
  61. ))