Prettier times

This commit is contained in:
RunasSudo 2017-12-12 22:14:24 +10:30
parent 6ba9b1369a
commit 98a8faf486
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
5 changed files with 62 additions and 43 deletions

View File

@ -16,6 +16,7 @@
import click
import flask
import timeago
from eos.core.objects import *
from eos.core.tasks import *
@ -154,6 +155,10 @@ def verify_election(electionid):
def inject_globals():
return {'eos': eos, 'eosweb': eosweb, 'SHA256': eos.core.hashing.SHA256}
@app.template_filter('pretty_date')
def pretty_date(dt):
return flask.Markup('<time datetime="{}" title="{}">{}</time>'.format(dt.strftime('%Y-%m-%dT%H:%M:%SZ'), dt.strftime('%Y-%m-%d %H:%M:%S UTC'), timeago.format(dt, datetime.now())))
# Tickle the plumbus every request
@app.before_request
def tick_scheduler():

View File

@ -32,6 +32,10 @@
text-decoration: underline;
}
time[title] {
text-decoration: underline dotted;
}
/* Default of 1.25rem is too small for our long lists… */
.ui.ordered.list, .ui.ordered.list .list, ol.ui.list, ol.ui.list ol {
margin-left: 1.75rem;

View File

@ -26,17 +26,26 @@
<div class="menu">
<div class="header">Active tasks</div>
{% for task in eos.core.tasks.TaskScheduler.active_tasks() %}
<div class="item">{{ task.label }}</div>
<div class="item">
{{ task.label }}
<br><small><i class="wait icon"></i> started {{ task.started_at|pretty_date }}</small>
</div>
{% endfor %}
<div class="divider"></div>
<div class="header">Pending tasks</div>
{% for task in eos.core.tasks.TaskScheduler.pending_tasks() %}
<div class="item">{{ task.label }}</div>
<div class="item">
{{ task.label }}
<br><small><i class="wait icon"></i> due {{ task.run_at|pretty_date }}</small>
</div>
{% endfor %}
<div class="divider"></div>
<div class="header">Recently completed tasks</div>
{% for task in eos.core.tasks.TaskScheduler.completed_tasks(3) %}
<div class="item">{% if task.status < 0 %}<i class="warning sign icon"></i> {% endif %}{{ task.label }}</div>
<div class="item">
{% if task.status < 0 %}<i class="warning sign icon"></i> {% endif %}{{ task.label }}
<br><small><i class="wait icon"></i> completed {{ task.completed_at|pretty_date }}</small>
</div>
{% endfor %}
</div>
</div>

View File

@ -33,56 +33,56 @@
{% else %}
<p><button class="ui huge button">Voting in this {{ election.kind }} has not yet opened</button></p>
{% endif %}
<p>
Voting in this {{ election.kind }}
{% if election.workflow.get_task('eos.base.workflow.TaskOpenVoting').status == Status.EXITED %}
opened at
{% if election.workflow.get_task('eos.base.workflow.TaskOpenVoting').get_entry_task().run_at %}
{{ election.workflow.get_task('eos.base.workflow.TaskOpenVoting').get_entry_task().run_at.strftime('%Y-%m-%d %H:%M:%S') }} UTC
according to schedule,
{% else %}
{{ election.workflow.get_task('eos.base.workflow.TaskOpenVoting').exited_at.strftime('%Y-%m-%d %H:%M:%S') }} UTC
at the administrator's discretion,
{% endif %}
{% else %}
is scheduled to open at
{% if election.workflow.get_task('eos.base.workflow.TaskOpenVoting').get_entry_task().run_at %}
{{ election.workflow.get_task('eos.base.workflow.TaskOpenVoting').get_entry_task().run_at.strftime('%Y-%m-%d %H:%M:%S') }} UTC,
{% else %}
the administrator's discretion,
{% endif %}
{% endif %}
and
{% if election.workflow.get_task('eos.base.workflow.TaskCloseVoting').status == Status.EXITED %}
closed at
{% if election.workflow.get_task('eos.base.workflow.TaskCloseVoting').get_entry_task().run_at %}
{{ election.workflow.get_task('eos.base.workflow.TaskCloseVoting').get_entry_task().run_at.strftime('%Y-%m-%d %H:%M:%S') }} UTC
according to schedule
{% else %}
{{ election.workflow.get_task('eos.base.workflow.TaskCloseVoting').exited_at.strftime('%Y-%m-%d %H:%M:%S') }} UTC
at the administrator's discretion
{% endif %}
{% else %}
is scheduled to close at
{% if election.workflow.get_task('eos.base.workflow.TaskCloseVoting').get_entry_task().run_at %}
{{ election.workflow.get_task('eos.base.workflow.TaskCloseVoting').get_entry_task().run_at.strftime('%Y-%m-%d %H:%M:%S') }} UTC.
{% else %}
the administrator's discretion.
{% endif %}
{% endif %}
</p>
{% else %}
<p><button class="ui huge button">This {{ election.kind }} is not yet ready for voting</button></p>
<p>The administrator of this {{ election.kind }} has not yet finished setting the election parameters. The details of the {{ election.kind }} may change at any time.</p>
{% endif %}
<p>
Voting in this {{ election.kind }}
{% if election.workflow.get_task('eos.base.workflow.TaskOpenVoting').status == Status.EXITED %}
opened
{% if election.workflow.get_task('eos.base.workflow.TaskOpenVoting').get_entry_task().run_at %}
{{ election.workflow.get_task('eos.base.workflow.TaskOpenVoting').get_entry_task().run_at|pretty_date }}
according to schedule,
{% else %}
{{ election.workflow.get_task('eos.base.workflow.TaskOpenVoting').exited_at|pretty_date }}
at the administrator's discretion,
{% endif %}
{% else %}
is scheduled to open
{% if election.workflow.get_task('eos.base.workflow.TaskOpenVoting').get_entry_task().run_at %}
{{ election.workflow.get_task('eos.base.workflow.TaskOpenVoting').get_entry_task().run_at|pretty_date }},
{% else %}
the administrator's discretion,
{% endif %}
{% endif %}
and
{% if election.workflow.get_task('eos.base.workflow.TaskCloseVoting').status == Status.EXITED %}
closed
{% if election.workflow.get_task('eos.base.workflow.TaskCloseVoting').get_entry_task().run_at %}
{{ election.workflow.get_task('eos.base.workflow.TaskCloseVoting').get_entry_task().run_at|pretty_date }}
according to schedule.
{% else %}
{{ election.workflow.get_task('eos.base.workflow.TaskCloseVoting').exited_at|pretty_date }}
at the administrator's discretion.
{% endif %}
{% else %}
is scheduled to close
{% if election.workflow.get_task('eos.base.workflow.TaskCloseVoting').get_entry_task().run_at %}
{{ election.workflow.get_task('eos.base.workflow.TaskCloseVoting').get_entry_task().run_at|pretty_date }}.
{% else %}
the administrator's discretion.
{% endif %}
{% endif %}
</p>
{% if (session.user and session.user.is_admin() and election.workflow.get_task('eos.base.workflow.TaskReleaseResults').status == Status.READY) or election.workflow.get_task('eos.base.workflow.TaskReleaseResults').status == Status.EXITED %}
<h2>Results</h2>
{% if election.workflow.get_task('eos.base.workflow.TaskReleaseResults').status == Status.EXITED %}
<p>Results were released at {{ election.workflow.get_task('eos.base.workflow.TaskReleaseResults').exited_at.strftime('%Y-%m-%d %H:%M:%S') }} UTC.</p>
<p>Results were released at {{ election.workflow.get_task('eos.base.workflow.TaskReleaseResults').exited_at|pretty_date }}.</p>
{% else %}
<div class="ui warning message">
This is a preview of the election results, shown only to you, the election administrator. To publicly release the results, you must do so from the <a href="{{ url_for('election_admin_summary', election_id=election._id) }}">‘Administrate this election’</a> tab.

View File

@ -18,6 +18,7 @@ pymongo==3.5.1
requests==2.18.4
requests-oauthlib==0.8.0
six==1.10.0
timeago==1.0.8
Transcrypt==3.6.60
typed-ast==1.1.0
urllib3==1.22