Skip to content

Commit c25fc16

Browse files
authored
Merge pull request #42 from elekto-io/display-info
Display candidate info
2 parents 83523b4 + 23657dc commit c25fc16

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

docs/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Documentation
2+
3+
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.

elekto/models/meta.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ def __init__(self, key):
6363

6464
if not os.path.exists(self.path):
6565
F.abort(404)
66+
else:
67+
self.build()
6668

6769
@staticmethod
6870
def all():
@@ -133,6 +135,9 @@ def results(self):
133135

134136
def voters(self):
135137
return utils.parse_yaml(os.path.join(self.path, Election.VOT))
138+
139+
def showfields(self):
140+
return dict.fromkeys(self.election['show_candidate_fields'], '')
136141

137142
def candidates(self):
138143
"""
@@ -164,5 +169,11 @@ def candidate(self, cid):
164169
candidate['key'] = cid
165170
candidate['description'] = utils.parse_md(
166171
utils.extract_candidate_description(md), False)
167-
172+
# return only the candidate optional fields that are listed in show_candidate_fields
173+
# unfilled fields are returned as '' so the label still displays
174+
candidate['fields'] = self.showfields()
175+
for info in candidate['info']:
176+
field = list(info.keys())[0]
177+
if field in candidate['fields']:
178+
candidate['fields'][field] = info[field]
168179
return candidate

elekto/templates/views/elections/candidate.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ <h1 class="banner-title space-lr">
2121
<p class="banner-subtitle space-lr">
2222
<small class="badge badge-green" style="text-transform: none;">{{ candidate['ID'] }}</small> | <span>Running for {{ election['name'] }}</span>
2323
</p>
24+
{% for fieldname, info in candidate['fields'].items() %}
25+
<p class="banner-subtitle space-lr">
26+
<small class="badge badge-green" style="text-transform: none;">{{ fieldname }}</small> | <span>{{ info }}</span>
27+
</p>
28+
{% endfor %}
2429
</div>
2530
<div class="space--md pb-1rem">
2631
<div class="description space-lr">

0 commit comments

Comments
 (0)