swissvotes.models.policy_area

Classes

PolicyArea

Helper class for handling of descriptors.

PolicyAreaDefinition

Helper class for all the policy areas and their translatable labels.

Module Contents

class swissvotes.models.policy_area.PolicyArea(value: str | list[int])[source]
class swissvotes.models.policy_area.PolicyArea(value: decimal.Decimal, level: int)

Helper class for handling of descriptors.

There are three levels of descriptors, each new level refining the given category.

Policy areas are internally represented as a string value containing the descriptor of all three levels separated by a comma, e.g. “1.12.121”.

Policy areas are stored in the dataset as float, with the pre-decimal part refering to the first level category and the decimal part to the category of the given level. For example:

Level 1 descriptor “1”: 1 Level 2 descriptor “1.12”: 1.12 Level 3 descriptor “1.12.121”: 1.121

__repr__() str[source]
__eq__(other: object) bool[source]
property level: int[source]
property descriptor: int[source]

Returns the highest descriptor, e.g. 121 if “1.12.121”.

property descriptor_path: list[int][source]

Returns all descriptors, e.g [1, 12, 121] if “1.12.121”.

property descriptor_decimal: decimal.Decimal[source]

Returns the descriptor as float for the dataset, e.g 1.121 if “1.12.121”.

property label: str[source]

Returns a translatable label of the highest descriptor, e.g. “Bundesverfassung” if “1.12.121”.

property label_path: list[str][source]

Returns translatable labels for all descriptor levels, e.g. [“Staatsordnung”, “Politisches System”, “Bundesverfassung”] if “1.12.121”.

html(request: onegov.swissvotes.request.SwissvotesRequest) markupsafe.Markup[source]
class swissvotes.models.policy_area.PolicyAreaDefinition(path: list[int] | None = None, label: str | None = None, children: list[PolicyAreaDefinition] | None = None)[source]

Helper class for all the policy areas and their translatable labels.

Example: Get the label of the policy area “1.12.121”:

PolicyAreaDefinition.all().get(1).get(12).get(121).label

path[source]
decimal = None[source]
value[source]
label[source]
children[source]
index[source]
get(key: int) PolicyAreaDefinition | None[source]

Returns the child with the given value.

static all() PolicyAreaDefinition[source]

Returns the tree of all policy areas.