support for observers
This commit is contained in:
35
manager.py
35
manager.py
@@ -10,19 +10,21 @@ import string
|
||||
import sys
|
||||
|
||||
|
||||
def insert_token(db, name, token):
|
||||
def insert_token(db, name, token, role):
|
||||
cur = db.cursor()
|
||||
|
||||
cur.execute("""
|
||||
INSERT INTO tokens (token, question_set, answered) VALUES (
|
||||
INSERT INTO tokens (token, question_set, answered, role) VALUES (
|
||||
?,
|
||||
?,
|
||||
'false'
|
||||
'false',
|
||||
?
|
||||
);
|
||||
""",
|
||||
(
|
||||
get_hash(token),
|
||||
name
|
||||
name,
|
||||
role
|
||||
)
|
||||
)
|
||||
db.commit()
|
||||
@@ -35,7 +37,7 @@ def manage_tokens(options):
|
||||
if options.list:
|
||||
cur = db.cursor()
|
||||
cur.execute(
|
||||
"SELECT token, answered FROM tokens WHERE question_set = ?",
|
||||
"SELECT token, answered FROM tokens WHERE question_set = ? AND role = 'voter'",
|
||||
(
|
||||
options.name,
|
||||
)
|
||||
@@ -47,12 +49,17 @@ def manage_tokens(options):
|
||||
"used" if row[1] == "true" else "unused"
|
||||
))
|
||||
return
|
||||
if options.role == 'voter':
|
||||
service = 'vote'
|
||||
if options.role == 'observer':
|
||||
service = 'observe'
|
||||
for i in range(options.number):
|
||||
N = 32
|
||||
token = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(N))
|
||||
insert_token(db, options.name, token)
|
||||
print("%s/vote/%s/%s"%(
|
||||
insert_token(db, options.name, token, options.role)
|
||||
print("%s/%s/%s/%s"%(
|
||||
options.prefix,
|
||||
service,
|
||||
options.name,
|
||||
token
|
||||
))
|
||||
@@ -90,11 +97,19 @@ def parse_options(database, questions):
|
||||
)
|
||||
parser_token.add_argument(
|
||||
'--prefix',
|
||||
action="store",
|
||||
dest="prefix",
|
||||
action = "store",
|
||||
dest = "prefix",
|
||||
default = "",
|
||||
help = "Prefix tokens with the server URL to automate emails etc.."
|
||||
)
|
||||
parser_token.add_argument(
|
||||
'--role',
|
||||
action = "store",
|
||||
dest = "role",
|
||||
default = "voter",
|
||||
choices = ['voter', 'observer'],
|
||||
help = "Add token for role. observer is a token that can only view the current status of the vote event."
|
||||
)
|
||||
parser_token.add_argument(
|
||||
'--list', '-l',
|
||||
action="store_true",
|
||||
@@ -177,6 +192,7 @@ def summary(options):
|
||||
out = summary_list(questions, answers, tokens)
|
||||
print(out)
|
||||
|
||||
|
||||
def summary_list(questions, answers, tokens):
|
||||
s = """# Tokens for this question set:
|
||||
# used: {used}, unused: {unused}, total: {total}
|
||||
@@ -266,6 +282,7 @@ def clear_tokens(options):
|
||||
db.commit()
|
||||
print("\nDeleted tokens for %s"%( options.name, ))
|
||||
|
||||
|
||||
def main(database, questions):
|
||||
options = parse_options(database, questions)
|
||||
if options.subparser_name == "list":
|
||||
|
||||
Reference in New Issue
Block a user