ballot.models.mixins

Module Contents

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

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

class ballot.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 ballot.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 ballot.models.mixins.TitleTranslationsMixin[source]

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

abstract property polymorphic_base: type[Any][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.

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

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

ballot.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 ballot.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]
last_modified() ColumnElement[datetime | None][source]
class ballot.models.mixins.ExplanationsPdfMixin[source]
files[source]
explanations_pdf[source]