list tokens
This commit is contained in:
8
abot.py
8
abot.py
@@ -77,9 +77,9 @@ def save_vote():
|
|||||||
return render_template('blank.html', message = "Not published")
|
return render_template('blank.html', message = "Not published")
|
||||||
if is_expired(form):
|
if is_expired(form):
|
||||||
return render_template('blank.html', message = "Voting has closed")
|
return render_template('blank.html', message = "Voting has closed")
|
||||||
#~ if is_closed_vote(form):
|
if is_closed_vote(form):
|
||||||
#~ if has_voted(key, token):
|
if has_voted(key, token):
|
||||||
#~ return render_template('blank.html', message = "Token already used")
|
return render_template('blank.html', message = "Token already used")
|
||||||
|
|
||||||
write_vote(key, token, request.form, form) # using request.
|
write_vote(key, token, request.form, form) # using request.
|
||||||
tokens = False
|
tokens = False
|
||||||
@@ -90,7 +90,7 @@ def save_vote():
|
|||||||
summary = True
|
summary = True
|
||||||
questions, answers = sort_summary(*get_summary(g.db, key))
|
questions, answers = sort_summary(*get_summary(g.db, key))
|
||||||
tokens = get_token_counts(g.db, key)
|
tokens = get_token_counts(g.db, key)
|
||||||
print(answers)
|
|
||||||
return render_template(
|
return render_template(
|
||||||
'thank_you.html',
|
'thank_you.html',
|
||||||
summary = summary,
|
summary = summary,
|
||||||
|
|||||||
27
manager.py
27
manager.py
@@ -28,10 +28,26 @@ def insert_token(db, name, token):
|
|||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
|
|
||||||
def add_token(options):
|
def manage_tokens(options):
|
||||||
if not is_key(options.name, options):
|
if not is_key(options.name, options):
|
||||||
raise Exception("%s does not exist, or is not a valid question set name"%( options.name, ))
|
raise Exception("%s does not exist, or is not a valid question set name"%( options.name, ))
|
||||||
db = open_db(options.db)
|
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):
|
for i in range(options.number):
|
||||||
N = 32
|
N = 32
|
||||||
token = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(N))
|
token = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(N))
|
||||||
@@ -80,6 +96,13 @@ def parse_options(database, questions):
|
|||||||
default = "",
|
default = "",
|
||||||
help = "Prefix tokens with the server URL to automate emails etc.."
|
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(
|
parser_token.add_argument(
|
||||||
dest = "name",
|
dest = "name",
|
||||||
help = "Name of the question set"
|
help = "Name of the question set"
|
||||||
@@ -249,7 +272,7 @@ def main(database, questions):
|
|||||||
if options.subparser_name == "list":
|
if options.subparser_name == "list":
|
||||||
list_question_sets(options)
|
list_question_sets(options)
|
||||||
if options.subparser_name == "token":
|
if options.subparser_name == "token":
|
||||||
add_token(options)
|
manage_tokens(options)
|
||||||
if options.subparser_name == "summary":
|
if options.subparser_name == "summary":
|
||||||
summary(options)
|
summary(options)
|
||||||
if options.subparser_name == "clear_votes":
|
if options.subparser_name == "clear_votes":
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ It works?
|
|||||||
- no
|
- no
|
||||||
|
|
||||||
# If a question is in HTML tags, it's not formatted
|
# 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
|
# + character is multi choice question
|
||||||
+ banana
|
+ banana
|
||||||
+ orange
|
+ orange
|
||||||
|
|||||||
Reference in New Issue
Block a user