from onegov.election_day import ElectionDayApp
from onegov.election_day.layouts import ElectionLayout
from onegov.election_day.models import Election
from onegov.election_day.security import MaybePublic
from onegov.election_day.utils import add_last_modified_header
from onegov.election_day.utils.election import get_lists_panachage_data
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from onegov.core.types import JSON_ro
from onegov.core.types import RenderData
from onegov.election_day.request import ElectionDayRequest
from webob.response import Response
@ElectionDayApp.json(
model=Election,
name='lists-panachage-data',
permission=MaybePublic
)
[docs]
def view_election_lists_panachage_data(
self: Election,
request: 'ElectionDayRequest'
) -> 'JSON_ro':
"""" View the panachage data as JSON. Used to for the panachage sankey
chart.
"""
return get_lists_panachage_data(self, request)
@ElectionDayApp.html(
model=Election,
name='lists-panachage-chart',
template='embed.pt',
permission=MaybePublic
)
[docs]
def view_election_lists_panachage_chart(
self: Election,
request: 'ElectionDayRequest'
) -> 'RenderData':
"""" View the panachage data as sankey chart. """
@request.after
def add_last_modified(response: 'Response') -> None:
add_last_modified_header(response, self.last_modified)
return {
'model': self,
'layout': ElectionLayout(self, request),
'type': 'lists-panachage-chart',
}
@ElectionDayApp.html(
model=Election,
name='lists-panachage',
template='election/lists_panachage.pt',
permission=MaybePublic
)
[docs]
def view_election_lists_panachage(
self: Election,
request: 'ElectionDayRequest'
) -> 'RenderData':
"""" The main view. """
layout = ElectionLayout(self, request, 'lists-panachage')
return {
'election': self,
'layout': layout
}
@ElectionDayApp.svg_file(
model=Election,
name='lists-panachage-svg',
permission=MaybePublic
)
[docs]
def view_election_lists_panachage_svg(
self: Election,
request: 'ElectionDayRequest'
) -> 'RenderData':
""" View the panachage as SVG. """
layout = ElectionLayout(self, request, 'lists-panachage')
return {
'path': layout.svg_path,
'name': layout.svg_name
}