election_day.utils.common
Attributes
Classes
Base class for protocol classes. |
|
Stores items in the order the keys were last added. |
Functions
Removes prefixed parent_connection_id from connection_id as introduced by |
|
|
Adds the give date to the response as Last-Modified header. |
|
Adds a header allowing the response being used in scripts. |
|
Adds the result of the principal. |
|
|
|
|
|
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: ...
- 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.
- 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]