from .tool.func import * async def vote_select(num = 1): with get_db_connect() as conn: curs = conn.cursor() num = str(num) curs.execute(db_change('select name, subject, data, type from vote where id = ? and user = ""'), [num]) data_list = curs.fetchall() if not data_list: return redirect(conn, '/vote') if data_list[0][3] == 'close' or data_list[0][3] == 'n_close': return redirect(conn, '/vote/end/' + num) if await acl_check('', 'vote', num) == 1: return redirect(conn, '/vote/end/' + num) curs.execute(db_change('select user from vote where id = ? and user = ?'), [num, ip_check()]) if curs.fetchall(): return redirect(conn, '/vote/end/' + num) curs.execute(db_change('select data from vote where id = ? and name = "end_date" and type = "option"'), [num]) db_data = curs.fetchall() time_limit = '' if db_data: time_limit = db_data[0][0] time_db = db_data[0][0].split()[0] time_today = get_time().split()[0] if time_today > time_db: return redirect(conn, '/vote/end/' + num) vote_data = re.findall(r'([^\n]+)', data_list[0][2].replace('\r', '')) if flask.request.method == 'POST': try: vaild_check = int(flask.request.form.get('vote_data', '0')) except: return redirect(conn, '/vote/' + num) if len(vote_data) - 1 < vaild_check: return redirect(conn, '/vote/' + num) curs.execute(db_change("insert into vote (name, id, subject, data, user, type) values ('', ?, '', ?, ?, 'select')"), [ num, str(vaild_check), ip_check() ]) return redirect(conn, '/vote/end/' + num) else: data = '