Skip to content
This repository has been archived by the owner on Sep 5, 2019. It is now read-only.

Commit

Permalink
Adds mandate allocation view to election compound
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Sommerhalder committed Mar 18, 2019
1 parent db7c20d commit a09f77c
Show file tree
Hide file tree
Showing 15 changed files with 201 additions and 34 deletions.
3 changes: 3 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Changelog
---------

- Adds mandate allocation view to election compound.
[msom]

- Fixes party results possibly not being downloadable.
[msom]

Expand Down
9 changes: 9 additions & 0 deletions onegov/election_day/forms/election_compound.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ class ElectionCompoundForm(Form):

show_party_strengths = BooleanField(
label=_("Party strengths"),
fieldset=_("Views"),
render_kw=dict(force_simple=True)
)

show_mandate_allocation = BooleanField(
label=_("Mandate allocation"),
fieldset=_("Views"),
render_kw=dict(force_simple=True)
)

Expand Down Expand Up @@ -118,6 +125,7 @@ def update_model(self, model):
model.shortcode = self.shortcode.data
model.related_link = self.related_link.data
model.show_party_strengths = self.show_party_strengths.data
model.show_mandate_allocation = self.show_mandate_allocation.data

elections = self.request.session.query(Election)
elections = elections.filter(Election.id.in_(self.elections.data))
Expand Down Expand Up @@ -146,4 +154,5 @@ def apply_model(self, model):
self.shortcode.data = model.shortcode
self.related_link.data = model.related_link
self.show_party_strengths.data = model.show_party_strengths
self.show_mandate_allocation.data = model.show_mandate_allocation
self.elections.data = [election.id for election in model.elections]
8 changes: 8 additions & 0 deletions onegov/election_day/layouts/election_compound.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def all_tabs(self):
return (
'districts',
'candidates',
'mandate-allocation',
'party-strengths',
'parties-panachage',
'data'
Expand All @@ -29,6 +30,8 @@ def title(self, tab=None):
return self.request.app.principal.label('districts')
if tab == 'candidates':
return _("Elected candidates")
if tab == 'mandate-allocation':
return _("Mandate allocation")
if tab == 'party-strengths':
return _("Party strengths")
if tab == 'parties-panachage':
Expand All @@ -41,6 +44,11 @@ def title(self, tab=None):
def tab_visible(self, tab):
if not self.has_results:
return False
if tab == 'mandate-allocation':
return (
self.model.show_mandate_allocation is True
and self.model.party_results.first() is not None
)
if tab == 'party-strengths':
return (
self.model.show_party_strengths is True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE 1.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-11-05 09:12+0100\n"
"PO-Revision-Date: 2018-11-05 09:15+0100\n"
"POT-Creation-Date: 2019-03-18 07:52+0100\n"
"PO-Revision-Date: 2019-03-18 07:53+0100\n"
"Last-Translator: Marc Sommerhalder <[email protected]>\n"
"Language-Team: German\n"
"Language: de_CH\n"
Expand All @@ -12,7 +12,7 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Lingua 3.12\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 2.2\n"
"X-Generator: Poedit 2.2.1\n"

msgid "Last change"
msgstr "Aktualisiert"
Expand Down Expand Up @@ -41,6 +41,9 @@ msgstr "Absolutes Mehr"
msgid "Tacit election"
msgstr "Stille Wahl"

msgid "Expats"
msgstr "Auslandschweizer"

msgid "Distinct district"
msgstr "Eindeutiger Wahlkreis"

Expand Down Expand Up @@ -89,6 +92,15 @@ msgstr "Relativ"
msgid "Elections"
msgstr "Wahlen"

msgid "Party strengths"
msgstr "Parteistärken"

msgid "Views"
msgstr "Ansichten"

msgid "Mandate allocation"
msgstr "Sitzzuteilung"

msgid "Cantonal"
msgstr "Kantonal"

Expand Down Expand Up @@ -324,9 +336,6 @@ msgstr ""
"proportional zu den Stimmen, blau eingefärbte Balken enthalten die Anzahl "
"der Mandate."

msgid "Party strengths"
msgstr "Parteistärken"

#.
#. Default: The diagram shows the votes and mandates of the parties. The rimmed
#. bars (left scale) correspond to the number of mandates, the colored bars
Expand Down Expand Up @@ -359,9 +368,6 @@ msgstr "Panaschierstatistik (Listen)"
msgid "Mandates"
msgstr "Mandate"

msgid "Expats"
msgstr "Auslandschweizer"

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-11-05 09:12+0100\n"
"PO-Revision-Date: 2018-11-05 09:15+0100\n"
"POT-Creation-Date: 2019-03-18 07:52+0100\n"
"PO-Revision-Date: 2019-03-18 07:58+0100\n"
"Last-Translator: Marc Sommerhalder <[email protected]>\n"
"Language-Team: \n"
"Language: fr_CH\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: xls-to-po 1.0\n"
"X-Generator: Poedit 2.2\n"
"X-Generator: Poedit 2.2.1\n"

msgid "Last change"
msgstr "Actualisé"
Expand Down Expand Up @@ -41,6 +41,9 @@ msgstr "Majorité absolue"
msgid "Tacit election"
msgstr "Élection tacite"

msgid "Expats"
msgstr "Suisses de l'étranger"

msgid "Distinct district"
msgstr "District unique"

Expand Down Expand Up @@ -89,6 +92,15 @@ msgstr "Relative"
msgid "Elections"
msgstr "Elections"

msgid "Party strengths"
msgstr "Force des partis"

msgid "Views"
msgstr "Vues"

msgid "Mandate allocation"
msgstr "Répartition des sièges"

msgid "Cantonal"
msgstr "Cantonal"

Expand Down Expand Up @@ -323,9 +335,6 @@ msgstr ""
"largeur des barres et des connexions est proportionnelle aux votes, les "
"barres de couleur bleue contiennent le nombre de mandats."

msgid "Party strengths"
msgstr "Force des partis"

#.
#. Default: The diagram shows the votes and mandates of the parties. The rimmed
#. bars (left scale) correspond to the number of mandates, the colored bars
Expand Down Expand Up @@ -357,9 +366,6 @@ msgstr "Panachage (listes)"
msgid "Mandates"
msgstr "Mandats"

msgid "Expats"
msgstr "Suisses de l'étranger"

msgid "Proposal and counter proposal rejected"
msgstr "Initiative et contre-projet rejetées"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-11-05 09:12+0100\n"
"PO-Revision-Date: 2018-11-05 09:16+0100\n"
"POT-Creation-Date: 2019-03-18 07:52+0100\n"
"PO-Revision-Date: 2019-03-18 07:56+0100\n"
"Last-Translator: Marc Sommerhalder <[email protected]>\n"
"Language-Team: \n"
"Language: it_CH\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: xls-to-po 1.0\n"
"X-Generator: Poedit 2.2\n"
"X-Generator: Poedit 2.2.1\n"

msgid "Last change"
msgstr "Aggiornato"
Expand Down Expand Up @@ -41,6 +41,9 @@ msgstr "Maggioranza assoluta"
msgid "Tacit election"
msgstr "Elezione tacita"

msgid "Expats"
msgstr "Svizzeri all'estero"

msgid "Distinct district"
msgstr "Distretto Unico"

Expand Down Expand Up @@ -89,6 +92,15 @@ msgstr "Relativo"
msgid "Elections"
msgstr "Elezioni"

msgid "Party strengths"
msgstr "Forza delle parti"

msgid "Views"
msgstr "Visualizzazioni"

msgid "Mandate allocation"
msgstr "Ripartizione dei seggi"

msgid "Cantonal"
msgstr "Cantonale"

Expand Down Expand Up @@ -323,9 +335,6 @@ msgstr ""
"liste. L'ampiezza delle barre e delle connessioni è proporzionale ai voti, "
"le barre colorate di blu contengono i numeri dei mandati."

msgid "Party strengths"
msgstr "Forza delle parti"

#.
#. Default: The diagram shows the votes and mandates of the parties. The rimmed
#. bars (left scale) correspond to the number of mandates, the colored bars
Expand Down Expand Up @@ -357,9 +366,6 @@ msgstr "Panachage (liste)"
msgid "Mandates"
msgstr "Mandati"

msgid "Expats"
msgstr "Svizzeri all'estero"

msgid "Proposal and counter proposal rejected"
msgstr "Iniziativa e controprogetto sono state rifiutate"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-11-05 09:12+0100\n"
"POT-Creation-Date: 2019-03-18 07:52+0100\n"
"PO-Revision-Date: 2018-11-05 12:07+0100\n"
"Last-Translator: Marc Sommerhalder <[email protected]>\n"
"Language-Team: \n"
Expand Down Expand Up @@ -40,6 +40,9 @@ msgstr "Maioritad absoluta"
msgid "Tacit election"
msgstr "Elecziun taciturna"

msgid "Expats"
msgstr "Svizzers a l'exteriur"

msgid "Distinct district"
msgstr "Clera regiun"

Expand Down Expand Up @@ -88,6 +91,15 @@ msgstr "Relativ"
msgid "Elections"
msgstr "Elecziuns"

msgid "Party strengths"
msgstr "Forza da las partidas"

msgid "Views"
msgstr ""

msgid "Mandate allocation"
msgstr ""

msgid "Cantonal"
msgstr "Sin plaun chantunal"

Expand Down Expand Up @@ -324,9 +336,6 @@ msgstr ""
"travs e da las colliaziuns è proporziunala a las vuschs, las travs blauas "
"cuntegnan il dumber da mandats."

msgid "Party strengths"
msgstr "Forza da las partidas"

#.
#. Default: The diagram shows the votes and mandates of the parties. The rimmed
#. bars (left scale) correspond to the number of mandates, the colored bars
Expand Down Expand Up @@ -359,9 +368,6 @@ msgstr "Statistica da panaschar (glistas)"
msgid "Mandates"
msgstr "Mandats"

msgid "Expats"
msgstr "Svizzers a l'exteriur"

msgid "Proposal and counter proposal rejected"
msgstr "Refusà l'iniziativa e la cuntraproposta"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<div metal:use-macro="layout.base" i18n:domain="onegov.election_day">
<tal:block metal:fill-slot="title">${election_compound.title}</tal:block>
<tal:block metal:fill-slot="before-content">
<div metal:use-macro="layout.macros['election_header']" tal:define="election election_compound" />
</tal:block>
<tal:block metal:fill-slot="content">

<div metal:use-macro="layout.macros['status_callout']" />

<tal:block tal:condition="layout.visible">

<h2 i18n:translate="">Results</h2>

<div metal:use-macro="layout.macros['election_compound_factoids']" />

<div metal:use-macro="layout.macros['tab_menu']" />

<h3 tal:content="layout.title()" />

<div metal:use-macro="layout.macros['party_strengths']" />

</tal:block>

<div metal:use-macro="layout.macros['related_link']" />

</tal:block>
</div>
1 change: 1 addition & 0 deletions onegov/election_day/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ def create_election_compound(client):
new.form['domain'] = 'canton'
new.form['elections'] = ['regional-election-a', 'regional-election-b']
new.form['show_party_strengths'] = True
new.form['show_mandate_allocation'] = True
new.form.submit()


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def test_election_compound_form_model(session):
model.shortcode = 'xy'
model.related_link = 'http://u.rl'
model.show_party_strengths = True
model.show_mandate_allocation = True
model.elections = [e1, e2]
session.add(model)

Expand All @@ -159,6 +160,7 @@ def test_election_compound_form_model(session):
assert form.shortcode.data == 'xy'
assert form.related_link.data == 'http://u.rl'
assert form.show_party_strengths.data is True
assert form.show_mandate_allocation.data is True
assert form.elections.data == ['e-1', 'e-2']

form.election_de.data = 'Some Elections (DE)'
Expand All @@ -170,6 +172,7 @@ def test_election_compound_form_model(session):
form.shortcode.data = 'yz'
form.related_link.data = 'http://ur.l'
form.show_party_strengths.data = False
form.show_mandate_allocation.data = False
form.elections.data = ['e-1', 'e-3', 'e-4']

form.request = DummyRequest(session=session)
Expand All @@ -186,4 +189,5 @@ def test_election_compound_form_model(session):
assert model.shortcode == 'yz'
assert model.related_link == 'http://ur.l'
assert form.show_party_strengths.data is False
assert form.show_mandate_allocation.data is False
assert sorted([e.id for e in model.elections]) == ['e-1', 'e-3']
Loading

0 comments on commit a09f77c

Please sign in to comment.