election_day.utils.common

Attributes

_T

_KT

_VT

_ParamT

Classes

HasNotifications

Base class for protocol classes.

LastUpdatedOrderedDict

Stores items in the order the keys were last added.

Functions

sublist_name_from_connection_id(→ str)

Removes prefixed parent_connection_id from connection_id as introduced by

add_last_modified_header(→ None)

Adds the give date to the response as Last-Modified header.

add_cors_header(→ None)

Adds a header allowing the response being used in scripts.

add_local_results(→ None)

Adds the result of the principal.

get_parameter(→ _ParamT | _T)

get_entity_filter(→ list[tuple[str, bool, str]])

replace_url(→ str)

Module Contents

class election_day.utils.common.HasNotifications[source]

Bases: Protocol

Base class for protocol classes.

Protocol classes are defined as:

class Proto(Protocol):
    def meth(self) -> int:
        ...

Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing).

For example:

class C:
    def meth(self) -> int:
        return 0

def func(x: Proto) -> int:
    return x.meth()

func(C())  # Passes static type check

See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as:

class GenProto(Protocol[T]):
    def meth(self) -> T:
        ...
notifications: sqlalchemy.orm.relationship[onegov.core.types.AppenderQuery[onegov.election_day.models.Notification]][source]
election_day.utils.common._T[source]
election_day.utils.common._KT[source]
election_day.utils.common._VT[source]
election_day.utils.common._ParamT[source]
election_day.utils.common.sublist_name_from_connection_id(conn_name: str, subconn_name: str) str[source]

Removes prefixed parent_connection_id from connection_id as introduced by sesam 2019.09

Parameters:
  • conn_name – list connection name aka parent_connection_id

  • subconn_name – subconnection name aka connection_id

class election_day.utils.common.LastUpdatedOrderedDict[source]

Bases: collections.OrderedDict[_KT, _VT]

Stores items in the order the keys were last added.

__setitem__(key: _KT, value: _VT) None[source]

Set self[key] to value.

election_day.utils.common.add_last_modified_header(response: webob.response.Response, last_modified: datetime | None) None[source]

Adds the give date to the response as Last-Modified header.

election_day.utils.common.add_cors_header(response: webob.response.Response) None[source]

Adds a header allowing the response being used in scripts.

election_day.utils.common.add_local_results(source: onegov.election_day.models.ArchivedResult, target: onegov.election_day.models.ArchivedResult, principal: Canton | Municipality, session: sqlalchemy.orm.Session) None[source]

Adds the result of the principal.

Municipalities are interested in their own result rather than the cantonal end result of votes. We query the result of the municipality within the given vote (source) and add it to the target.

election_day.utils.common.get_parameter(request: onegov.election_day.request.ElectionDayRequest, name: str, type_: type[_ParamT], default: _T) _ParamT | _T[source]
election_day.utils.common.get_entity_filter(request: onegov.election_day.request.ElectionDayRequest, item: onegov.election_day.models.Election, view: str, selected: str | None) list[tuple[str, bool, str]][source]
election_day.utils.common.replace_url(url: str, start: str | None) str[source]