diff --git a/doc/source/_exts/candidates.py b/doc/source/_exts/candidates.py index 59b7581b..464ce94f 100644 --- a/doc/source/_exts/candidates.py +++ b/doc/source/_exts/candidates.py @@ -113,6 +113,9 @@ def build_lists(app): class CandidatesDirective(Directive): def run(self): + if not utils.election_is_running(): + return [] + rst = '.. include:: ' if utils.is_tc_election(): rst += 'tc.rst' diff --git a/openstack_election/utils.py b/openstack_election/utils.py index 7e09d1f5..f2184074 100644 --- a/openstack_election/utils.py +++ b/openstack_election/utils.py @@ -184,6 +184,18 @@ def is_tc_election(): return conf.get('election_type', '').lower() == 'tc' +def election_is_running(): + # Assume that the start of the first item in and the end of the last + # defines is a reasonable approximation to "election is running" + timeline = conf.get('timeline') + if timeline: + start = timeline[0]['start'] + end = timeline[-1]['end'] + now = datetime.datetime.utcnow().replace(tzinfo=pytz.utc) + return start <= now <= end + return False + + def build_candidates_list(election=conf['release']): election_path = os.path.join(CANDIDATE_PATH, election) if os.path.exists(election_path):