swissvotes.models.policy_area ============================= .. py:module:: swissvotes.models.policy_area Classes ------- .. autoapisummary:: swissvotes.models.policy_area.PolicyArea swissvotes.models.policy_area.PolicyAreaDefinition Module Contents --------------- .. py:class:: PolicyArea(value: str | list[int]) 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 .. py:method:: from_url_param(s: str) -> PolicyArea | None :classmethod: Validates and constructs a PolicyArea from a URL parameter. Returns None for empty or invalid values. Callers that need to reject invalid input (e.g. URL converters) should raise ValueError on None. A valid value has at most 3 all-numeric components separated by dots where each component starts with the previous one (e.g. "1", "1.12", "1.12.121"). .. py:method:: __repr__() -> str .. py:method:: __eq__(other: object) -> bool .. py:method:: __hash__() -> int .. py:property:: level :type: int .. py:property:: descriptor :type: int The highest descriptor, e.g. 121 if "1.12.121". .. py:property:: descriptor_path :type: list[int] All descriptors, e.g [1, 12, 121] if "1.12.121". .. py:property:: descriptor_decimal :type: decimal.Decimal The descriptor as a decimal for the dataset, e.g. 1.121 if "1.12.121". .. py:property:: label :type: str A translatable label of the highest descriptor, e.g. "Bundesverfassung" if "1.12.121". .. py:property:: label_path :type: list[str] Translatable labels for all descriptor levels, e.g. ["Staatsordnung", "Politisches System", "Bundesverfassung"] if "1.12.121". .. py:method:: html(request: onegov.swissvotes.request.SwissvotesRequest) -> markupsafe.Markup .. py:class:: PolicyAreaDefinition(path: list[int] | None = None, label: str | None = None, children: list[PolicyAreaDefinition] | None = None) 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 .. py:attribute:: path :value: [] .. py:attribute:: decimal :value: None .. py:attribute:: value .. py:attribute:: label :value: None .. py:attribute:: children :value: [] .. py:attribute:: index .. py:method:: get(key: int) -> PolicyAreaDefinition | None Returns the child with the given value. .. py:method:: all() -> PolicyAreaDefinition :staticmethod: Returns the tree of all policy areas.