Skip to content

Commit

Permalink
Election Day: Distinguish between direct and indirect counter proposals.
Browse files Browse the repository at this point in the history
TYPE: Feature
LINK: OGC-1675
  • Loading branch information
msom authored Jun 8, 2024
1 parent 5c5351d commit f2ee087
Show file tree
Hide file tree
Showing 19 changed files with 349 additions and 104 deletions.
1 change: 1 addition & 0 deletions src/onegov/election_day/collections/archived_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ def update(
result.answer = item.answer or ''
result.nays_percentage = item.nays_percentage
result.yeas_percentage = item.yeas_percentage
result.direct = item.direct

if add_result:
self.session.add(result)
Expand Down
41 changes: 40 additions & 1 deletion src/onegov/election_day/forms/vote.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from onegov.core.utils import normalize_for_url
from onegov.election_day import _
from onegov.election_day.models import Ballot
from onegov.election_day.models import ComplexVote
from onegov.election_day.models import Vote
from onegov.form import Form
from onegov.form.fields import ChosenSelectField
Expand All @@ -23,7 +24,6 @@
from typing import cast
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from onegov.election_day.models import ComplexVote
from onegov.election_day.request import ElectionDayRequest


Expand Down Expand Up @@ -82,6 +82,20 @@ class VoteForm(Form):
default='simple'
)

direct = RadioField(
label=_("Counter Proposal"),
fieldset=_("Properties"),
choices=[
('direct', _("Direct (Counter Proposal)")),
('indirect', _("Indirect (Counter Proposal)")),
],
validators=[
InputRequired()
],
default='direct',
depends_on=('type', 'complex')
)

domain = RadioField(
label=_("Domain"),
fieldset=_("Properties"),
Expand Down Expand Up @@ -129,6 +143,20 @@ class VoteForm(Form):
render_kw={'force_simple': True},
)

direct_vocabulary = RadioField(
label=_("Counter Proposal"),
fieldset=_("View options"),
choices=[
('direct', _("Direct (Counter Proposal)")),
('indirect', _("Indirect (Counter Proposal)")),
],
validators=[
InputRequired()
],
default='direct',
depends_on=('tie_breaker_vocabulary', 'y')
)

title_de = StringField(
label=_("German"),
fieldset=_("Title of the the vote/proposal"),
Expand Down Expand Up @@ -316,6 +344,7 @@ def on_request(self) -> None:

if principal.id != 'zg':
self.delete_field('tie_breaker_vocabulary')
self.delete_field('direct_vocabulary')

self.domain.choices = [
(key, text) for key, text in principal.domains_vote.items()
Expand Down Expand Up @@ -353,6 +382,10 @@ def update_model(self, model: Vote) -> None:
if self.id and self.id.data:
model.id = self.id.data
model.external_id = self.external_id.data
if isinstance(model, ComplexVote):
model.direct = self.direct.data == 'direct'
elif self.direct_vocabulary is not None:
model.direct = self.direct_vocabulary.data == 'direct'
assert self.date.data is not None
model.date = self.date.data
model.domain = self.domain.data
Expand Down Expand Up @@ -457,6 +490,12 @@ def apply_model(self, model: Vote) -> None:
self.related_link_label_it.data = link_labels.get('it_CH', '')
self.related_link_label_rm.data = link_labels.get('rm_CH', '')

if isinstance(model, ComplexVote):
self.direct.data = 'direct' if model.direct else 'indirect'
elif self.direct_vocabulary is not None:
self.direct_vocabulary.data = (
'direct' if model.direct else 'indirect'
)
self.date.data = model.date
self.domain.data = model.domain
if model.domain == 'municipality':
Expand Down
5 changes: 4 additions & 1 deletion src/onegov/election_day/layouts/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ def subject(self, model: 'Election | ElectionCompound | Vote') -> str:
if model.answer == 'rejected':
result = _("Rejected")
if model.answer == 'counter-proposal':
result = _("Counter proposal accepted")
if model.direct:
result = _("Direct counter proposal accepted")
else:
result = _("Indirect counter proposal accepted")

parts = (self.model_title(model), self.request.translate(result))
return ' - '.join(part for part in parts if part)
Expand Down
36 changes: 30 additions & 6 deletions src/onegov/election_day/layouts/vote.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def title(self, tab: str | None = None) -> str:
if tab.startswith('proposal'):
return _("Proposal")
if tab.startswith('counter-proposal'):
return _("Counter Proposal")
return self.label("Counter Proposal")
if tab.startswith('tie-breaker'):
return _("Tie-Breaker")
if tab == 'data':
Expand Down Expand Up @@ -132,22 +132,42 @@ def label(self, value: str) -> str:
self.ballot.type == 'tie-breaker'
or self.model.tie_breaker_vocabulary
)
if value == 'Counter Proposal':
if self.direct:
return _('Direct Counter Proposal')
return _('Indirect Counter Proposal')
if value == 'Yay':
return _('Proposal') if tie_breaker else _('Yay')
if value == 'Nay':
return _('Counter Proposal') if tie_breaker else _('Nay')
if not tie_breaker:
return _('Nay')
if self.direct:
return _('Direct Counter Proposal')
return _('Indirect Counter Proposal')
if value == 'Yeas':
return _('Proposal') if tie_breaker else _('Yeas')
if value == 'Nays':
return _('Counter Proposal') if tie_breaker else _('Nays')
if not tie_breaker:
return _('Nays')
if self.direct:
return _('Direct Counter Proposal')
return _('Indirect Counter Proposal')
if value == 'Yes %':
return _('Proposal %') if tie_breaker else _('Yes %')
if value == 'No %':
return _('Counter proposal %') if tie_breaker else _('No %')
if not tie_breaker:
return _('No %')
if self.direct:
return _('Direct Counter Proposal %')
return _('Indirect Counter Proposal %')
if value == 'Accepted':
return _('Proposal') if tie_breaker else _('Accepted')
if value == 'Rejected':
return _('Counter Proposal') if tie_breaker else _('Rejected')
if not tie_breaker:
return _('Rejected')
if self.direct:
return _('Direct Counter Proposal')
return _('Indirect Counter Proposal')

return self.principal.label(value)

Expand Down Expand Up @@ -250,14 +270,18 @@ def main_view(self) -> str:
def answer(self) -> str | None:
return self.model.answer

@cached_property
def direct(self) -> bool:
return self.model.direct

@cached_property
def menu(self) -> 'NestedMenu':
if self.type == 'complex':
result: NestedMenu = []

for title, prefix in (
(_("Proposal"), 'proposal'),
(_("Counter Proposal"), 'counter-proposal'),
(self.label("Counter Proposal"), 'counter-proposal'),
(_("Tie-Breaker"), 'tie-breaker')
):
submenu: NestedMenu = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE 1.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-06-06 08:32+0200\n"
"POT-Creation-Date: 2024-06-08 12:57+0200\n"
"PO-Revision-Date: 2022-03-24 15:35+0100\n"
"Last-Translator: Marc Sommerhalder <[email protected]>\n"
"Language-Team: German\n"
Expand Down Expand Up @@ -257,7 +257,7 @@ msgid "Rejected"
msgstr "abgelehnt"

msgid "Counter Proposal"
msgstr "Gegenentwurf"
msgstr "Gegenentwurf/Gegenvorschlag"

msgid "Federal"
msgstr "National"
Expand Down Expand Up @@ -591,7 +591,7 @@ msgid "Simple Vote"
msgstr "Einfache Vorlage"

msgid "Vote with Counter-Proposal"
msgstr "Vorlage mit Gegenentwurf"
msgstr "Vorlage mit Gegenentwurf/Gegenvorschlag"

msgid "Compound of Elections"
msgstr "Verbundene Wahl"
Expand Down Expand Up @@ -652,22 +652,28 @@ msgid "Proposal / Results"
msgstr "Vorlage / Resultate"

msgid "External ID of counter proposal"
msgstr "Externe ID des Gegenvorschlags"
msgstr "Externe ID des Gegenentwurfs/Gegenvorschlags"

msgid "External ID of tie breaker"
msgstr "Externe ID der Stichfrage"

msgid "Direct (Counter Proposal)"
msgstr "Direkt (Gegenentwurf)"

msgid "Indirect (Counter Proposal)"
msgstr "Indirekt (Gegenvorschlag)"

msgid "Display as tie-breaker"
msgstr "Als Stichfrage darstellen"

msgid "Title of the the vote/proposal"
msgstr "Titel der Abstimmung/der Vorlage"
msgstr "Titel der Abstimmung/Vorlage"

msgid "Short title of the the vote/proposal"
msgstr "Kurztitel der Abstimmung/der Vorlage"
msgstr "Kurztitel der Abstimmung/Vorlage"

msgid "Title of the counter proposal"
msgstr "Titel des Gegenentwurfs"
msgstr "Titel des Gegenentwurfs/Gegenvorschlags"

msgid "Title of the tie breaker"
msgstr "Titel der Stichfrage"
Expand Down Expand Up @@ -712,9 +718,12 @@ msgstr "Neue Zwischenresultate"
msgid "Final results"
msgstr "Schlussresultate"

msgid "Counter proposal accepted"
msgid "Direct counter proposal accepted"
msgstr "Gegenentwurf angenommen"

msgid "Indirect counter proposal accepted"
msgstr "Gegenvorschlag angenommen"

msgid "Manage"
msgstr "Verwalten"

Expand Down Expand Up @@ -763,6 +772,12 @@ msgstr "Vorlage"
msgid "Tie-Breaker"
msgstr "Stichfrage"

msgid "Direct Counter Proposal"
msgstr "Gegenentwurf"

msgid "Indirect Counter Proposal"
msgstr "Gegenvorschlag"

msgid "Yay"
msgstr "Ja"

Expand All @@ -781,12 +796,15 @@ msgstr "Vorlage %"
msgid "Yes %"
msgstr "Ja %"

msgid "Counter proposal %"
msgstr "Gegenentwurf %"

msgid "No %"
msgstr "Nein %"

msgid "Direct Counter Proposal %"
msgstr "Gegenentwurf %"

msgid "Indirect Counter Proposal %"
msgstr "Gegenvorschlag %"

#, python-format
msgid "Regional (${on})"
msgstr "Regional (${on})"
Expand Down Expand Up @@ -1204,18 +1222,24 @@ msgstr "SMS-Benachrichtigung abonnieren"
msgid "Stop SMS subscription"
msgstr "SMS-Abonnement beenden"

msgid "Proposal and counter proposal rejected"
msgid "Proposal and direct counter proposal rejected"
msgstr "Initative und Gegenentwurf abgelehnt"

msgid "Proposal and indirect counter proposal rejected"
msgstr "Initative und Gegenvorschlag abgelehnt"

msgid "Proposal accepted"
msgstr "Initiative angenommen"

msgid "Tie breaker in favor of the proposal"
msgstr "Stichfrage zugunsten der Initiative"

msgid "Tie breaker in favor of the counter proposal"
msgid "Tie breaker in favor of the direct counter proposal"
msgstr "Stichfrage zugunsten des Gegenentwurfs"

msgid "Tie breaker in favor of the indirect counter proposal"
msgstr "Stichfrage zugunsten des Gegenvorschlags"

msgid "Download a PDF with all the results:"
msgstr "Ein PDF mit allen Resultaten kann hier heruntergeladen werden:"

Expand Down
Loading

0 comments on commit f2ee087

Please sign in to comment.