Use election_type configuration to display correct candidates

Now that we have the election_type in configuration.yaml we can stop
manually switching the include in index.rst as we open the election.

Depends-On: https://review.openstack.org/561075
Change-Id: I33fbbc9e2c0e2dfcdf38290bc103b126cffdea0a
This commit is contained in:
Tony Breeds 2018-04-12 10:11:18 +10:00
parent 37e4aa3a85
commit 81b79183d8
4 changed files with 29 additions and 6 deletions

View File

@ -18,6 +18,10 @@ import jinja2.environment
import os
import yaml
from docutils import nodes
from docutils.parsers.rst import Directive
from docutils.statemachine import ViewList
from sphinx.util.nodes import nested_parse_with_titles
from openstack_election import utils
@ -107,6 +111,25 @@ def build_lists(app):
open(toc, "w").write("\n".join(previous_toc))
class CandidatesDirective(Directive):
def run(self):
rst = '.. include:: '
if utils.is_tc_election():
rst += 'tc.rst'
else:
rst += 'ptl.rst'
result = ViewList()
for idx, line in enumerate(rst.splitlines()):
result.append(line, 'CandidatesDirective', idx)
node = nodes.paragraph()
node.document = self.state.document
nested_parse_with_titles(self.state, result, node)
return node.children
def setup(app):
app.info('loading candidates extension')
app.connect('builder-inited', build_lists)
app.add_directive('candidates', CandidatesDirective)
return {'version': '0.1'}

View File

@ -9,9 +9,7 @@ OpenStack Election
See `Election system`_, `PTL details`_ and `TC details`_.
.. Below is the official list of candidates for the current round.
.. TODO: Change from tc.rst to ptl.rst when PTL rounds starts
.. .. include:: tc.rst
.. candidates::
Previous elections

View File

@ -180,10 +180,11 @@ def dir2name(name, projects):
raise ValueError(('%s does not match any project' % (name)))
def build_candidates_list(election=conf['release']):
def is_tc_election():
return conf.get('election_type', '').lower() == 'tc'
def is_tc_election():
return conf.get('election_type', '').lower() == 'tc'
def build_candidates_list(election=conf['release']):
election_path = os.path.join(CANDIDATE_PATH, election)
if os.path.exists(election_path):
project_list = os.listdir(election_path)

View File

@ -7,3 +7,4 @@ PyYAML>=3.10 # MIT
requests>=2.14.2 # Apache-2.0
ndg-httpsclient>=0.4.2;python_version<'3.0' # BSD
PrettyTable<0.8,>=0.7.1 # BSD
docutils>=0.11 # OSI-Approved Open Source, Public Domain