election/openstack_election/config.py
Tristan Cacqueray 8791d36b37 Rewrite the event logic in javascript
The current events extension is computing the statuses at build time,
which is getting incorrect when an event is outdated until there is
a rebuild. This change fix that by doing the event status computation
at load time in javascript.

Moreover this change removes an unused import in utils.

Change-Id: Ifd1b84ff0182cf9bb7950da3d59f36c83019ac30
2017-01-30 01:48:11 +00:00

41 lines
1.4 KiB
Python

# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import datetime
import pytz
import yaml
TIME_FMT = "%b %d, %Y %H:%M %Z"
ISO_FMT = "%Y-%m-%dT%H:%M"
# Load configuration.yaml and create datetime objects
def parse_datetime(iso_format):
date = datetime.datetime.strptime(iso_format, ISO_FMT)
return date.replace(tzinfo=pytz.utc)
def load_conf():
conf = yaml.safe_load(open('configuration.yaml'))
for key in ('start', 'end', 'email_deadline'):
date = parse_datetime(conf['timeframe'][key])
conf['timeframe'][key] = date
conf['timeframe'][key+'_str'] = date.strftime(TIME_FMT)
for event in conf['timeline']:
for key in ('start', 'end'):
date = parse_datetime(event[key])
event[key] = date
event[key+'_iso'] = date.strftime(ISO_FMT)
event[key+'_str'] = date.strftime(TIME_FMT)
return conf