swissvotes.collections.votes

Attributes

T

Classes

SwissVoteCollection

A collection of votes.

Module Contents

swissvotes.collections.votes.T[source]
class swissvotes.collections.votes.SwissVoteCollection(app: onegov.swissvotes.app.SwissvotesApp, page: int = 0, from_date: datetime.date | None = None, to_date: datetime.date | None = None, legal_form: list[int] | None = None, result: list[int] | None = None, policy_area: list[str] | None = None, term: str | None = None, full_text: bool | None = None, position_federal_council: list[int] | None = None, position_national_council: list[int] | None = None, position_council_of_states: list[int] | None = None, sort_by: str | None = None, sort_order: str | None = None)[source]

Bases: onegov.core.collection.Pagination[onegov.swissvotes.models.SwissVote]

A collection of votes.

Supports pagination, filtering, sorting, exporting (CSV/XLSX) and batch adding/updating.

page: int | None[source]
batch_size = 20[source]
initial_sort_by = 'date'[source]
initial_sort_order = 'descending'[source]
default_sort_order = 'ascending'[source]
SORT_BYS = ('date', 'legal_form', 'result', 'result_people_yeas_p', 'title', 'result_turnout')[source]
SORT_ORDERS = ('ascending', 'descending')[source]
app[source]
session[source]
from_date[source]
to_date[source]
legal_form[source]
result[source]
policy_area[source]
term[source]
full_text[source]
position_federal_council[source]
position_national_council[source]
position_council_of_states[source]
sort_by[source]
sort_order[source]
add(**kwargs: Any) onegov.swissvotes.models.SwissVote[source]
subset() Query[SwissVote][source]

Returns an SQLAlchemy query containing all records that should be considered for pagination.

__eq__(other: object) bool[source]

Returns True if the current and the other Pagination instance are equal. Used to find the current page in a list of pages.

default() Self[source]

Returns the votes unfiltered and ordered by default.

property page_index: int[source]

The current page.

page_by_index(page: int) Self[source]

Returns the requested page.

property current_sort_by: str[source]

Returns the currently used sorting key.

Defaults to a reasonable value.

property current_sort_order: str[source]

Returns the currently used sorting order.

Defaults to a reasonable value.

sort_order_by_key(sort_by: str | None) str[source]

Returns the sort order by key.

Defaults to ‘unsorted’.

by_order(sort_by: str | None) Self[source]

Returns the votes ordered by the given key.

property order_by: ColumnElement[Any][source]

Returns an SqlAlchemy expression for ordering queries based on the current sorting key and ordering.

property offset: int[source]

The current position in the batch.

property previous: Self | None[source]

The previous page.

property next: Self | None[source]

The next page.

property term_filter_numeric: list[ColumnElement[bool]][source]

Returns a list of SqlAlchemy filter statements matching possible numeric attributes based on the term.

property term_filter_text: list[ColumnElement[bool]][source]

Returns a list of SqlAlchemy filter statements matching possible fulltext attributes based on the term.

property term_filter: list[ColumnElement[bool]][source]

Returns a list of SqlAlchemy filter statements based on the search term.

query() Query[SwissVote][source]

Returns the votes matching to the current filters and order.

by_bfs_number(bfs_number: decimal.Decimal | str) onegov.swissvotes.models.SwissVote | None[source]

Returns the vote with the given BFS number.

property available_descriptors: list[set[decimal.Decimal]][source]

Returns a list of the used descriptor values (level 1-3).

update(votes: Iterable[SwissVote]) tuple[int, int][source]

Adds or updates the given votes.

update_metadata(metadata: dict[decimal.Decimal, dict[str, dict[str, Any]]]) tuple[int, int][source]
property last_modified: datetime | None[source]

Returns the last change of any votes.

export_csv(file: IO[str]) None[source]

Exports all votes according to the code book.

export_xlsx(file: IO[str]) None[source]

Exports all votes according to the code book.