From 66b60835c3f19d7a34528b00ef62d21d37d93763 Mon Sep 17 00:00:00 2001 From: Josh Berkus Date: Wed, 6 Oct 2021 16:31:03 -0700 Subject: [PATCH 1/3] Display the show-candidate_fields on the candidate screen. Signed-off-by: Josh Berkus --- docs/README.md | 3 +++ elekto/models/meta.py | 11 ++++++++++- elekto/templates/views/elections/candidate.html | 5 +++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index e69de29..ea9021b 100644 --- a/docs/README.md +++ b/docs/README.md @@ -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. diff --git a/elekto/models/meta.py b/elekto/models/meta.py index 442f80c..a150844 100644 --- a/elekto/models/meta.py +++ b/elekto/models/meta.py @@ -133,6 +133,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): """ @@ -164,5 +167,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 diff --git a/elekto/templates/views/elections/candidate.html b/elekto/templates/views/elections/candidate.html index 2237160..d38d6c9 100644 --- a/elekto/templates/views/elections/candidate.html +++ b/elekto/templates/views/elections/candidate.html @@ -21,6 +21,11 @@

+ {% for fieldname, info in candidate['fields'].items() %} +

+ {{ fieldname }} | {{ info }} +

+ {% endfor %}
From 20ae3512761909bafd4a09220199e5014c2fc659 Mon Sep 17 00:00:00 2001 From: Josh Berkus Date: Wed, 6 Oct 2021 16:48:06 -0700 Subject: [PATCH 2/3] Fix self reference issue. Signed-off-by: Josh Berkus --- elekto/models/meta.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/elekto/models/meta.py b/elekto/models/meta.py index a150844..ae2c85a 100644 --- a/elekto/models/meta.py +++ b/elekto/models/meta.py @@ -63,6 +63,8 @@ def __init__(self, key): if not os.path.exists(self.path): F.abort(404) + else: + self.build() @staticmethod def all(): From 23657dc5c97f35e98aac49cb6e24e30d5ab38e06 Mon Sep 17 00:00:00 2001 From: Josh Berkus Date: Wed, 6 Oct 2021 16:51:10 -0700 Subject: [PATCH 3/3] Tinker with text alignment. Signed-off-by: Josh Berkus --- elekto/templates/views/elections/candidate.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elekto/templates/views/elections/candidate.html b/elekto/templates/views/elections/candidate.html index d38d6c9..f2763db 100644 --- a/elekto/templates/views/elections/candidate.html +++ b/elekto/templates/views/elections/candidate.html @@ -22,7 +22,7 @@

{{ candidate['ID'] }} | Running for {{ election['name'] }}

{% for fieldname, info in candidate['fields'].items() %} -

+

{% endfor %}