list tokens

This commit is contained in:
Ville Rantanen
2018-12-05 12:41:30 +02:00
parent 59c371cd79
commit a12b9e9462
3 changed files with 30 additions and 7 deletions

View File

@@ -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,

View File

@@ -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":

View File

@@ -23,7 +23,7 @@ It works?
- no
# If a question is in HTML tags, it's not formatted
<p>Fruits</p>
<p>Fruits <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/2/29/Paul_C%C3%A9zanne_-_Fruit_and_a_Jug_on_a_Table_-_Google_Art_Project.jpg/250px-Paul_C%C3%A9zanne_-_Fruit_and_a_Jug_on_a_Table_-_Google_Art_Project.jpg"</img></p>
# + character is multi choice question
+ banana
+ orange