From 98a8faf486d67210e3dc4df039791acab7a17cf6 Mon Sep 17 00:00:00 2001 From: RunasSudo Date: Tue, 12 Dec 2017 22:14:24 +1030 Subject: [PATCH] Prettier times --- eosweb/core/main.py | 5 ++ eosweb/core/static/css/main.css | 4 + eosweb/core/templates/active_tasks_menu.html | 15 +++- eosweb/core/templates/election/view/view.html | 80 +++++++++---------- requirements.txt | 1 + 5 files changed, 62 insertions(+), 43 deletions(-) diff --git a/eosweb/core/main.py b/eosweb/core/main.py index b0aa3fe..9f0d627 100644 --- a/eosweb/core/main.py +++ b/eosweb/core/main.py @@ -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(''.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(): diff --git a/eosweb/core/static/css/main.css b/eosweb/core/static/css/main.css index 53b39f2..3849153 100644 --- a/eosweb/core/static/css/main.css +++ b/eosweb/core/static/css/main.css @@ -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; diff --git a/eosweb/core/templates/active_tasks_menu.html b/eosweb/core/templates/active_tasks_menu.html index 2240172..4a9c778 100644 --- a/eosweb/core/templates/active_tasks_menu.html +++ b/eosweb/core/templates/active_tasks_menu.html @@ -26,17 +26,26 @@ diff --git a/eosweb/core/templates/election/view/view.html b/eosweb/core/templates/election/view/view.html index 59e9008..a553b7c 100644 --- a/eosweb/core/templates/election/view/view.html +++ b/eosweb/core/templates/election/view/view.html @@ -33,56 +33,56 @@ {% else %}

{% endif %} - -

- 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 %} -

{% else %}

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.

{% endif %} +

+ 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 %} +

+ {% 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 %}

Results

{% if election.workflow.get_task('eos.base.workflow.TaskReleaseResults').status == Status.EXITED %} -

Results were released at {{ election.workflow.get_task('eos.base.workflow.TaskReleaseResults').exited_at.strftime('%Y-%m-%d %H:%M:%S') }} UTC.

+

Results were released at {{ election.workflow.get_task('eos.base.workflow.TaskReleaseResults').exited_at|pretty_date }}.

{% else %}
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 ‘Administrate this election’ tab. diff --git a/requirements.txt b/requirements.txt index 0898d37..318addc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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