Refactor timeline structure
This change modifies the timeline structure to describe a start and end date instead of two different events. Moreover this change adds: * the number of days remaining until the next event. * a 'next' status when current event haven't started yet Change-Id: Ib76b0315a7409a8442c1be6f8341b0596c1d56ae
This commit is contained in:
parent
c97fdd8b65
commit
4d473dc0bd
@ -1,10 +1,14 @@
|
||||
---
|
||||
timelines:
|
||||
- {'date': '2016-09-12T00:00', 'name': 'PTL nomination starts'}
|
||||
- {'date': '2016-09-18T23:45', 'name': 'PTL nomination ends'}
|
||||
- {'date': '2016-09-19T00:00', 'name': 'PTL elections begins'}
|
||||
- {'date': '2016-09-25T23:45', 'name': 'PTL elections ends'}
|
||||
- {'date': '2016-09-26T00:00', 'name': 'TC nomination starts'}
|
||||
- {'date': '2016-10-01T23:45', 'name': 'TC nomination ends'}
|
||||
- {'date': '2016-10-03T00:00', 'name': 'TC elections begins'}
|
||||
- {'date': '2016-10-09T23:45', 'name': 'TC elections ends'}
|
||||
timeline:
|
||||
- name: 'PTL nomination'
|
||||
start: '2016-09-12T00:00'
|
||||
end: '2016-09-18T23:45'
|
||||
- name: 'PTL elections'
|
||||
start: '2016-09-19T00:00'
|
||||
end: '2016-09-25T23:45'
|
||||
- name: 'TC nomination'
|
||||
start: '2016-09-26T00:00'
|
||||
end: '2016-10-01T23:45'
|
||||
- name: 'TC elections'
|
||||
start: '2016-10-03T00:00'
|
||||
end: '2016-10-09T23:45'
|
||||
|
@ -5,17 +5,17 @@
|
||||
<script>
|
||||
var events_timeline = [
|
||||
{% for event in events %}
|
||||
{ date: "{{ event['date'] }}", name: "{{ event['name'] }}" },
|
||||
{ start: "{{ event['start'] }}", end: "{{ event['end'] }}", name: "{{ event['name'] }}" },
|
||||
{% endfor %}
|
||||
];
|
||||
</script>
|
||||
<br /><br />
|
||||
|
||||
|
||||
+------------------------------------+------------------------------------+-----------+
|
||||
| Events | Date | Status |
|
||||
+====================================+====================================+===========+
|
||||
+------------------------------------+------------------------------------+------------------------------------+-----------+
|
||||
| Events | Start Date | End Date | Status |
|
||||
+====================================+====================================+====================================+===========+
|
||||
{% for event in events %}
|
||||
| {{ "%29s" % event['name_str'] }} | {{ "%29s" % event['date_str'] }} | {{ "%7s" % event['status'] }} |
|
||||
+------------------------------------+------------------------------------+-----------+
|
||||
| {{ "%29s" % event['name_str'] }} | {{ "%29s" % event['start_str'] }} | {{ "%29s" % event['end_str'] }} | {{ "%7s" % event['status'] }} |
|
||||
+------------------------------------+------------------------------------+------------------------------------+-----------+
|
||||
{% endfor %}
|
||||
|
@ -24,31 +24,43 @@ from openstack_election import utils
|
||||
|
||||
def build_timer(app):
|
||||
app.add_javascript("event_timer.js")
|
||||
# add better text for tabulatted planning
|
||||
now = time.time()
|
||||
outdated = '*'
|
||||
for ev in utils.conf['timelines']:
|
||||
d, h = ev['date'].split('T')
|
||||
epoch_time = calendar.timegm(
|
||||
time.strptime(ev['date'], "%Y-%m-%dT%H:%M"))
|
||||
ev['status'] = 'past'
|
||||
if epoch_time > now:
|
||||
if outdated == '*':
|
||||
# Mark upcoming event as bold
|
||||
ev['status'] = 'current'
|
||||
outdated = '**'
|
||||
else:
|
||||
ev['status'] = 'future'
|
||||
outdated = ''
|
||||
ev['date_str'] = "%s%s, %s UTC%s" % (outdated, d, h, outdated)
|
||||
ev['name_str'] = "%s%s%s" % (outdated, ev['name'], outdated)
|
||||
first_event = True
|
||||
for ev in utils.conf['timeline']:
|
||||
ds, hs = ev['start'].split('T')
|
||||
de, he = ev['end'].split('T')
|
||||
start_time = calendar.timegm(
|
||||
time.strptime(ev['start'], "%Y-%m-%dT%H:%M"))
|
||||
end_time = calendar.timegm(
|
||||
time.strptime(ev['end'], "%Y-%m-%dT%H:%M"))
|
||||
|
||||
if start_time > now:
|
||||
ev['status'] = 'future'
|
||||
elif end_time > now:
|
||||
ev['status'] = 'current'
|
||||
else:
|
||||
ev['status'] = 'past'
|
||||
|
||||
if first_event and ev['status'] == 'future':
|
||||
ev['status'] = 'next'
|
||||
first_event = False
|
||||
|
||||
mark = ''
|
||||
if ev['status'] == 'current':
|
||||
mark = '**'
|
||||
elif ev['status'] == 'past':
|
||||
mark = '*'
|
||||
|
||||
ev['start_str'] = "%s%s, %s UTC%s" % (mark, ds, hs, mark)
|
||||
ev['end_str'] = "%s%s, %s UTC%s" % (mark, de, he, mark)
|
||||
ev['name_str'] = "%s%s%s" % (mark, ev['name'], mark)
|
||||
output_file = os.path.join(".", "doc", "source", "events.rst")
|
||||
with open(output_file, "w") as out:
|
||||
template_dir = os.path.join(".", "doc", "source", "_exts")
|
||||
loader = jinja2.FileSystemLoader(template_dir)
|
||||
env = jinja2.environment.Environment(trim_blocks=True, loader=loader)
|
||||
template = env.get_template("events.jinja")
|
||||
out.write(template.render({'events': utils.conf['timelines']}))
|
||||
out.write(template.render({'events': utils.conf['timeline']}))
|
||||
|
||||
|
||||
def setup(app):
|
||||
|
@ -1,25 +1,33 @@
|
||||
/* Licensed under the Apache License, Version 2.0
|
||||
*/
|
||||
var event_date;
|
||||
var now = parseInt((new Date).getTime() / 1000)
|
||||
var now = parseInt((new Date).getTime() / 1000);
|
||||
|
||||
function startTime() {
|
||||
var delta = parseInt(event_date - (new Date).getTime() / 1000)
|
||||
var hours = parseInt(delta / 3600)
|
||||
var minutes = parseInt( delta / 60 ) % 60
|
||||
var seconds = delta % 60
|
||||
document.getElementById('eventtimer').innerHTML = hours+'h'+minutes+'m'+seconds+'s'
|
||||
var t = setTimeout(startTime, 500)
|
||||
var delta = parseInt(event_date - (new Date).getTime() / 1000);
|
||||
var days = parseInt(delta / (3600 * 24));
|
||||
var hours = parseInt(delta / 3600) % 24;
|
||||
var minutes = parseInt( delta / 60 ) % 60;
|
||||
var seconds = delta % 60;
|
||||
document.getElementById('eventtimer').innerHTML = days+'d'+hours+'h'+minutes+'m'+seconds+'s';
|
||||
var t = setTimeout(startTime, 500);
|
||||
}
|
||||
|
||||
function setup_timeline() {
|
||||
for (i = 0; i < events_timeline.length; i++) {
|
||||
var current_event = events_timeline[i];
|
||||
event_date = Date.parse(current_event.date) / 1000
|
||||
event_date = Date.parse(current_event.start) / 1000;
|
||||
if (event_date > now) {
|
||||
document.getElementById('eventname').innerHTML = 'Next event is '+current_event.name+' in'
|
||||
event_date = Date.parse(current_event.date) / 1000
|
||||
startTime(current_event.date)
|
||||
break
|
||||
document.getElementById('eventname').innerHTML = current_event.name+' starts in';
|
||||
startTime();
|
||||
break;
|
||||
}
|
||||
event_date = Date.parse(current_event.end) / 1000;
|
||||
if (event_date > now) {
|
||||
document.getElementById('eventname').innerHTML = current_event.name+' ends in';
|
||||
startTime();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
$(document).ready(setup_timeline)
|
||||
$(document).ready(setup_timeline);
|
||||
|
@ -60,7 +60,7 @@ def load_exceptions():
|
||||
|
||||
|
||||
def get_event(event_name):
|
||||
for e in conf['timelines']:
|
||||
for e in conf['timeline']:
|
||||
if e['name'] == event_name:
|
||||
d = datetime.datetime.strptime(e['date'], "%Y-%m-%dT%H:%M")
|
||||
return d.replace(tzinfo=pytz.utc)
|
||||
|
Loading…
Reference in New Issue
Block a user