election_day.models.mixins

Classes

DomainOfInfluenceMixin

Defines the scope of a principal, an election, an election compound

StatusMixin

Mixin providing status indication for votes and elections.

TitleTranslationsMixin

Adds a helper to return the translation of the title without depending

IdFromTitlesMixin

LastModifiedMixin

Mixin providing created/modified timestamps for all records.

ExplanationsPdfMixin

Functions

summarized_property(→ Column[int])

Adds an attribute as hybrid_property which returns the sum of the

Module Contents

class election_day.models.mixins.DomainOfInfluenceMixin[source]

Defines the scope of a principal, an election, an election compound or a vote.

The following domains of influence are supported: - federation: The vote or election is nation wide. - canton: The vote or election takes place in one canton only. - region: The election takes place in one region of a canton only. - district: The election takes place in one district of a canton only. - municipality: The vote or election takes place in one municipality only. - none: The election takes place in certain municipalities only.

property domain: Column[DomainOfInfluence][source]
class election_day.models.mixins.StatusMixin[source]

Mixin providing status indication for votes and elections.

property status: Column[Status | None][source]
property completed: bool[source]

Returns True, if the election or vote is completed.

The status is evaluated in the first place. If the status is not known, it is guessed from the progress / counted fields.

class election_day.models.mixins.TitleTranslationsMixin[source]

Adds a helper to return the translation of the title without depending on the locale of the request.

title_translations: sqlalchemy.Column[collections.abc.Mapping[str, str]] | sqlalchemy.Column[collections.abc.Mapping[str, str] | None][source]
get_title(locale: str, default_locale: str | None = None) str | None[source]

Returns the requested translation of the title, falls back to the given default locale if provided.

class election_day.models.mixins.IdFromTitlesMixin[source]
property session_manager: onegov.core.orm.SessionManager | None[source]
property polymorphic_base: type[Any][source]
Abstractmethod:

get_short_title(locale: str, default_locale: str | None = None) str | None[source]

Returns the requested translation of the short title, falls back to the full title.

id_from_title(session: sqlalchemy.orm.Session) str[source]

Returns a unique, user friendly id derived from the title.

election_day.models.mixins.summarized_property(name: str) Column[int][source]

Adds an attribute as hybrid_property which returns the sum of the underlying results if called.

Requires the class to define two aggregation functions.

Usage:

class Model():
    votes = summarized_property('votes')

    results = relationship('Result', ...)

    def aggregate_results(self, attribute):
        return sum(getattr(res, attribute) for res in self.results)

    @classmethod
    def aggregate_results_expression(cls, attribute):
        expr = select([func.sum(getattr(Result, attribute))])
        expr = expr.where(Result.xxx_id == cls.id)
        expr = expr.label(attribute)
        return expr
class election_day.models.mixins.LastModifiedMixin[source]

Bases: onegov.core.orm.mixins.TimestampMixin

Mixin providing created/modified timestamps for all records.

The columns are deferred loaded as this is primarily for logging and future forensics.

property last_result_change: Column[datetime | None][source]
last_modified() datetime | None[source]
class election_day.models.mixins.ExplanationsPdfMixin[source]
files[source]
explanations_pdf[source]