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
This commit is contained in:
Tony Breeds 2018-04-12 10:34:50 +10:00
parent 81b79183d8
commit 6c223e6e97
2 changed files with 15 additions and 0 deletions

View File

@ -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'

View File

@ -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):