diff --git a/abot.py b/abot.py index 8ea0713..3145df8 100644 --- a/abot.py +++ b/abot.py @@ -77,9 +77,9 @@ def save_vote(): return render_template('blank.html', message = "Not published") if is_expired(form): return render_template('blank.html', message = "Voting has closed") - #~ if is_closed_vote(form): - #~ if has_voted(key, token): - #~ return render_template('blank.html', message = "Token already used") + if is_closed_vote(form): + if has_voted(key, token): + return render_template('blank.html', message = "Token already used") write_vote(key, token, request.form, form) # using request. tokens = False @@ -90,7 +90,7 @@ def save_vote(): summary = True questions, answers = sort_summary(*get_summary(g.db, key)) tokens = get_token_counts(g.db, key) - print(answers) + return render_template( 'thank_you.html', summary = summary, diff --git a/manager.py b/manager.py index ca18940..6985f28 100644 --- a/manager.py +++ b/manager.py @@ -28,10 +28,26 @@ def insert_token(db, name, token): db.commit() -def add_token(options): +def manage_tokens(options): if not is_key(options.name, options): raise Exception("%s does not exist, or is not a valid question set name"%( options.name, )) db = open_db(options.db) + if options.list: + cur = db.cursor() + cur.execute( + "SELECT token, answered FROM tokens WHERE question_set = ?", + ( + options.name, + ) + ) + for row in cur: + print("%s/vote/%s/%s (%s)"%( + options.prefix, + options.name, + row[0], + "used" if row[1] == "true" else "unused" + )) + return for i in range(options.number): N = 32 token = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(N)) @@ -80,6 +96,13 @@ def parse_options(database, questions): default = "", help = "Prefix tokens with the server URL to automate emails etc.." ) + parser_token.add_argument( + '--list', '-l', + action="store_true", + dest="list", + default = False, + help = "List existing tokens, instead of generating more" + ) parser_token.add_argument( dest = "name", help = "Name of the question set" @@ -249,7 +272,7 @@ def main(database, questions): if options.subparser_name == "list": list_question_sets(options) if options.subparser_name == "token": - add_token(options) + manage_tokens(options) if options.subparser_name == "summary": summary(options) if options.subparser_name == "clear_votes": diff --git a/questions/multi_question.txt b/questions/multi_question.txt index 3f382ab..6f60823 100644 --- a/questions/multi_question.txt +++ b/questions/multi_question.txt @@ -23,7 +23,7 @@ It works? - no # If a question is in HTML tags, it's not formatted -
Fruits
+Fruits ![]()