diff --git a/eos/base/election.py b/eos/base/election.py index e563142..62cf3dc 100644 --- a/eos/base/election.py +++ b/eos/base/election.py @@ -119,11 +119,23 @@ class ListChoiceQuestion(Question): def pretty_answer(self, answer): if len(answer.choices) == 0: return '(blank votes)' - return ', '.join([self.choices[choice].name for choice in answer.choices]) + flat_choices = self.flatten_choices() + return ', '.join([flat_choices[choice].name for choice in answer.choices]) def max_bits(self): answer = self.answer_type(choices=list(range(len(self.choices)))) return len(EosObject.to_json(EosObject.serialise_and_wrap(answer))) * 8 + + def flatten_choices(self): + # Return a flat list of Choices, without Tickets + flat_choices = [] + for choice in self.choices: + if isinstance(choice, Ticket): + for choice2 in choice.choices: + flat_choices.append(choice2) + else: + flat_choices.append(choice) + return flat_choices class ApprovalAnswer(Answer): choices = ListField(IntField()) @@ -140,6 +152,16 @@ class PreferentialQuestion(ListChoiceQuestion): class Choice(EmbeddedObject): name = StringField() party = StringField(default=None) + + @property + def party_or_ticket(self): + if self.party is not None: + return self.party + else: + ticket = self.recurse_parents(Ticket) + if ticket: + return ticket.name + return None class Ticket(EmbeddedObject): name = StringField() diff --git a/eosweb/core/static/css/main.css b/eosweb/core/static/css/main.css index 99eacc2..a700e29 100644 --- a/eosweb/core/static/css/main.css +++ b/eosweb/core/static/css/main.css @@ -109,10 +109,14 @@ text-align: center; } -.preferential-choice .party-name { +.preferential-choice .party-name, .preferential-choice .ticket-party-name { font-style: italic; } +.ticket .ticket-party-name { + display: none; +} + .ticket > .content > .party-name { min-height: 2em; } diff --git a/eosweb/core/static/nunjucks/question/approval/selections_make.html b/eosweb/core/static/nunjucks/question/approval/selections_make.html index 1526e6f..20d47cf 100644 --- a/eosweb/core/static/nunjucks/question/approval/selections_make.html +++ b/eosweb/core/static/nunjucks/question/approval/selections_make.html @@ -26,7 +26,7 @@
- +
{% endfor %} diff --git a/eosweb/core/static/nunjucks/question/approval/selections_review.html b/eosweb/core/static/nunjucks/question/approval/selections_review.html index 6f43277..8f686a8 100644 --- a/eosweb/core/static/nunjucks/question/approval/selections_review.html +++ b/eosweb/core/static/nunjucks/question/approval/selections_review.html @@ -20,7 +20,7 @@ {% for choice in booth.answers[loop.index0].value.choices %}
-
{{ question.choices.__getitem__(choice) }}
+
{{ question.choices.__getitem__(choice).name }}{% if question.choices.__getitem__(choice).party %}{{ question.choices.__getitem__(choice).party }}{% endif %}
{% else %}
diff --git a/eosweb/core/static/nunjucks/question/preferential/selections_make.html b/eosweb/core/static/nunjucks/question/preferential/selections_make.html index 6284312..121341d 100644 --- a/eosweb/core/static/nunjucks/question/preferential/selections_make.html +++ b/eosweb/core/static/nunjucks/question/preferential/selections_make.html @@ -34,12 +34,22 @@

You have selected more than the maximum allowed number of choices. To proceed, you must deselect some choices by dragging them from the blue box back to the grey box.

+{% set flat_choices = election.questions.__getitem__(questionNum).flatten_choices() %} + {% macro printchoice(choice, ticket=None) %} -
+
{{ choice.name }}
- {% if (ticket and choice.party and choice.party != ticket.name) or (not ticket and choice.party) %}
{{ choice.party }}
{% endif %} + {% if choice.party %} + {% if (ticket and choice.party != ticket.name) or not ticket %} +
{{ choice.party }}
+ {% else %} +
{{ choice.party }}
+ {% endif %} + {% elif ticket %} +
{{ ticket.name }}
+ {% endif %}
{% endmacro %} @@ -51,7 +61,7 @@ {% for choice in election.questions.__getitem__(questionNum).choices.impl %} {% if choice.choices %} {# Ticket #} -
+
{{ choice.name }}
@@ -71,6 +81,7 @@ diff --git a/eosweb/core/static/nunjucks/question/preferential/selections_review.html b/eosweb/core/static/nunjucks/question/preferential/selections_review.html index 49b98fe..9e048ef 100644 --- a/eosweb/core/static/nunjucks/question/preferential/selections_review.html +++ b/eosweb/core/static/nunjucks/question/preferential/selections_review.html @@ -16,11 +16,13 @@ along with this program. If not, see . #} +{% set flat_choices = question.flatten_choices() %} + {% if booth.answers[loop.index0].value.choices.length > 0 %}
{% for choice in booth.answers[loop.index0].value.choices %}
-
{{ question.choices.__getitem__(choice) }}
+
{{ flat_choices[choice].name }}{% if flat_choices[choice].party_or_ticket %} – {{ flat_choices[choice].party_or_ticket }}{% endif %}
{% endfor %}
diff --git a/eosweb/core/templates/election/view/booth.html b/eosweb/core/templates/election/view/booth.html index 8f80707..a294d62 100644 --- a/eosweb/core/templates/election/view/booth.html +++ b/eosweb/core/templates/election/view/booth.html @@ -55,6 +55,7 @@ booth = { "questionNum": 0, "answers": [], + "q_state": [] }; } resetBooth(); @@ -136,6 +137,7 @@ techDetails = '

Technical details: ' + err + '

'; } $("#booth-content").html('

We were unable to display the next page of the voting booth. For your security, your ballot selections have been cleared. Please try again. If this problem persists, contact the {{ election.kind }} administrator.

' + techDetails + '
'); + console.error(err); } function showTemplate(template, opts, destination) {