From 6c223e6e977ba1b3e51750e492af4d9bbecb9505 Mon Sep 17 00:00:00 2001 From: Tony Breeds Date: Thu, 12 Apr 2018 10:34:50 +1000 Subject: [PATCH] Hide the candidate list if building the docs outside an election When we close an election and add the results database we'll rebuild (and publish) the docs Take that opportunity to remove auto-magically remove the candidates list from the index page Change-Id: Iedca12846f6ae291d6c6e1cd8f6ba769f3c8e5ee --- doc/source/_exts/candidates.py | 3 +++ openstack_election/utils.py | 12 ++++++++++++ 2 files changed, 15 insertions(+) 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):