Skip to content

Commit

Permalink
Merge pull request #42 from elekto-io/display-info
Browse files Browse the repository at this point in the history
Display candidate info
  • Loading branch information
jberkus authored Oct 6, 2021
2 parents 83523b4 + 23657dc commit c25fc16
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
3 changes: 3 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Documentation

Primary elekto documentation is in [the Elekto Docs repo](https://github.com/elekto-io/docs) and not here. This directory contains some design documents from the early work on Elekto.
13 changes: 12 additions & 1 deletion elekto/models/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ def __init__(self, key):

if not os.path.exists(self.path):
F.abort(404)
else:
self.build()

@staticmethod
def all():
Expand Down Expand Up @@ -133,6 +135,9 @@ def results(self):

def voters(self):
return utils.parse_yaml(os.path.join(self.path, Election.VOT))

def showfields(self):
return dict.fromkeys(self.election['show_candidate_fields'], '')

def candidates(self):
"""
Expand Down Expand Up @@ -164,5 +169,11 @@ def candidate(self, cid):
candidate['key'] = cid
candidate['description'] = utils.parse_md(
utils.extract_candidate_description(md), False)

# return only the candidate optional fields that are listed in show_candidate_fields
# unfilled fields are returned as '' so the label still displays
candidate['fields'] = self.showfields()
for info in candidate['info']:
field = list(info.keys())[0]
if field in candidate['fields']:
candidate['fields'][field] = info[field]
return candidate
5 changes: 5 additions & 0 deletions elekto/templates/views/elections/candidate.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ <h1 class="banner-title space-lr">
<p class="banner-subtitle space-lr">
<small class="badge badge-green" style="text-transform: none;">{{ candidate['ID'] }}</small> | <span>Running for {{ election['name'] }}</span>
</p>
{% for fieldname, info in candidate['fields'].items() %}
<p class="banner-subtitle space-lr">
<small class="badge badge-green" style="text-transform: none;">{{ fieldname }}</small> | <span>{{ info }}</span>
</p>
{% endfor %}
</div>
<div class="space--md pb-1rem">
<div class="description space-lr">
Expand Down

0 comments on commit c25fc16

Please sign in to comment.