diff --git a/configuration.yaml b/configuration.yaml index 210a20ca..cd123247 100644 --- a/configuration.yaml +++ b/configuration.yaml @@ -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' diff --git a/doc/source/_exts/events.jinja b/doc/source/_exts/events.jinja index 7c0427bb..5f040318 100644 --- a/doc/source/_exts/events.jinja +++ b/doc/source/_exts/events.jinja @@ -5,17 +5,17 @@

-+------------------------------------+------------------------------------+-----------+ -| 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 %} diff --git a/doc/source/_exts/events.py b/doc/source/_exts/events.py index 039865bc..0d75a627 100644 --- a/doc/source/_exts/events.py +++ b/doc/source/_exts/events.py @@ -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): diff --git a/doc/source/_static/event_timer.js b/doc/source/_static/event_timer.js index 1991b7d5..f58eedf2 100644 --- a/doc/source/_static/event_timer.js +++ b/doc/source/_static/event_timer.js @@ -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); diff --git a/openstack_election/utils.py b/openstack_election/utils.py index dbd357f4..c6170b3b 100644 --- a/openstack_election/utils.py +++ b/openstack_election/utils.py @@ -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)