from functools import cached_property
from onegov.election_day.layouts.default import DefaultLayout
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from datetime import datetime
from onegov.election_day.models import Election
from onegov.election_day.models import ElectionCompound
from onegov.election_day.models import ElectionCompoundPart
from onegov.election_day.models import Vote
from onegov.election_day.request import ElectionDayRequest
from onegov.file import File
[docs]
class DetailLayout(DefaultLayout):
""" A common base layout for election and votes which caches some values
used in the macros.
"""
[docs]
model: 'Election | ElectionCompound | ElectionCompoundPart | Vote'
[docs]
request: 'ElectionDayRequest'
@cached_property
[docs]
def has_results(self) -> bool:
return self.model.has_results
@cached_property
[docs]
def completed(self) -> bool:
return self.model.completed
@cached_property
[docs]
def last_result_change(self) -> 'datetime | None':
return self.model.last_result_change
@cached_property
[docs]
def last_modified(self) -> 'datetime | None':
return self.model.last_modified
@cached_property
@cached_property
@cached_property
[docs]
def explanations_pdf(self) -> 'File | None':
return getattr(self.model, 'explanations_pdf', None)
@cached_property
[docs]
def show_map(self) -> bool:
if (
self.principal.domain == 'canton'
and getattr(self.model, 'domain', None) == 'municipality'
):
return False
return self.principal.is_year_available(self.model.date.year)