help to print votes and questions

This commit is contained in:
Ville Rantanen
2018-12-15 17:40:10 +02:00
parent a996edbc65
commit 0312a33115
2 changed files with 120 additions and 4 deletions

View File

@@ -173,7 +173,7 @@ def is_voter(key, token):
)
return len(cur.fetchall()) > 0
def parse_form(key):
def parse_form(key, questions = None, debug = None):
form = {
'expires': None,
'opens': None,
@@ -188,7 +188,9 @@ def parse_form(key):
key = secure_filename(key)
try:
current_question = 0
with open(os.path.join(app.config['QUESTIONS'], key + ".txt"), "rt", encoding = "UTF-8") as fp:
if questions == None:
questions = app.config['QUESTIONS']
with open(os.path.join(questions, key + ".txt"), "rt", encoding = "UTF-8") as fp:
for row in fp:
if row.strip() == "":
continue
@@ -197,7 +199,10 @@ def parse_form(key):
continue
if rowsl.startswith("title: "):
form['title'] = row[6:].strip()
g.title = row[6:].strip()
try:
g.title = row[6:].strip()
except RuntimeError:
pass
continue
if rowsl.startswith("expires: "):
form['expires'] = parse_row_date(row)
@@ -242,7 +247,9 @@ def parse_form(key):
})
return form
except Exception as err:
if app.config['DEBUG']:
if debug == None:
debug = app.config['DEBUG']
if debug:
raise err
return False