support for delayed opening. css changes
This commit is contained in:
35
utils.py
35
utils.py
@@ -131,10 +131,15 @@ def is_draft(form):
|
||||
def is_expired(form):
|
||||
if form['expires'] == None:
|
||||
return False
|
||||
|
||||
return datetime.now(timezone.utc) > form['expires']
|
||||
|
||||
|
||||
def is_opened(form):
|
||||
if form['opens'] == None:
|
||||
return True
|
||||
return datetime.now(timezone.utc) > form['opens']
|
||||
|
||||
|
||||
def is_key(key, cli_opts = False):
|
||||
key = secure_filename(key)
|
||||
|
||||
@@ -171,11 +176,14 @@ def is_voter(key, token):
|
||||
def parse_form(key):
|
||||
form = {
|
||||
'expires': None,
|
||||
'opens': None,
|
||||
'draft': False,
|
||||
'vote_style': "closed",
|
||||
'show_results': False,
|
||||
'questions': [],
|
||||
'title': ""
|
||||
'title': "",
|
||||
'can_submit': True,
|
||||
'message': ''
|
||||
}
|
||||
key = secure_filename(key)
|
||||
try:
|
||||
@@ -194,6 +202,9 @@ def parse_form(key):
|
||||
if rowsl.startswith("expires: "):
|
||||
form['expires'] = parse_row_date(row)
|
||||
continue
|
||||
if rowsl.startswith("opens: "):
|
||||
form['opens'] = parse_row_date(row)
|
||||
continue
|
||||
if rowsl.startswith("draft: "):
|
||||
if rowsl == "draft: true":
|
||||
form['draft'] = True
|
||||
@@ -225,7 +236,7 @@ def parse_form(key):
|
||||
'choices': [],
|
||||
'multichoices': [],
|
||||
'index': current_question + 1,
|
||||
'name': row.strip().rstrip("_:").rstrip(),
|
||||
'name': row.strip().rstrip("_").rstrip(),
|
||||
'open_question': row.strip().endswith("___"),
|
||||
'autoformat': not rowsl.startswith("<")
|
||||
})
|
||||
@@ -237,7 +248,7 @@ def parse_form(key):
|
||||
|
||||
|
||||
def parse_row_date(row):
|
||||
row = row[9:].strip()
|
||||
row = " ".join(row.split(" ")[1:]).strip()
|
||||
if row.lower() == "none":
|
||||
return None
|
||||
try:
|
||||
@@ -304,12 +315,18 @@ def sort_summary(questions, answers):
|
||||
return questions, sorted_answer_list
|
||||
|
||||
|
||||
def time_to_expiry(form):
|
||||
if form['expires'] == None:
|
||||
return "Never"
|
||||
def time_to(what, form):
|
||||
if not what in ('expires','opens'):
|
||||
raise AttributeError("Dont know that attribute")
|
||||
|
||||
time_to_go = form['expires'] - datetime.now(timezone.utc)
|
||||
if form[what] == None:
|
||||
if what == 'expires':
|
||||
return "Never"
|
||||
if what == 'opens':
|
||||
return "None"
|
||||
|
||||
time_to_go = form[what] - datetime.now(timezone.utc)
|
||||
time_to_go = ".".join(str(time_to_go).split('.')[0:-1])[0:-3]
|
||||
|
||||
#time_to_go.microseconds = 0
|
||||
return "%s (%s to go)"%( form['expires'], time_to_go )
|
||||
return "%s (%s to go)"%( form[what], time_to_go )
|
||||
|
||||
Reference in New Issue
Block a user