sortables
sortables
Sortable items management for scenarios.
Classes
SortableError
Bases: Exception
Base sortable error
Sortable
Bases: Base
Represents one sortable order. - If payload is a flat list, yields one Sortable. - If payload is a dict (heat_network), yields one Sortable per subtype.
Source code in src/pyetm/models/base.py
Functions
name
is_valid_update
Returns a WarningCollector with validation warnings without updating the current object
Source code in src/pyetm/models/sortables.py
validate_type
classmethod
Validate that type is a non-empty string
Source code in src/pyetm/models/sortables.py
validate_subtype
classmethod
Validate subtype if provided
Source code in src/pyetm/models/sortables.py
validate_order
classmethod
Validate that order is a list and check for duplicates
Source code in src/pyetm/models/sortables.py
validate_sortable_consistency
Additional validation for the entire sortable
Source code in src/pyetm/models/sortables.py
from_json
classmethod
:param data: (sortable_type, payload) - payload list → yield Sortable(type, order) - payload dict → yield Sortable(type, subtype, order) for each subtype
Source code in src/pyetm/models/sortables.py
Sortables
Bases: Base
A flat collection of Sortable instances, regardless of whether the source JSON was nested.
Source code in src/pyetm/models/base.py
Functions
names
is_valid_update
Returns a dict mapping sortable names to their WarningCollectors when errors were found
:param updates: Dict mapping sortable names to new orders :return: Dict mapping sortable names to WarningCollectors
Source code in src/pyetm/models/sortables.py
update
Update the orders of specified sortables with validation and warning display.
Invalid orders are rejected (not applied) to maintain data integrity. Warnings are automatically displayed for invalid orders and non-existent sortables. Warnings from previous updates are cleared to show only current operation issues.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
updates
|
Dict[str, list[Any]]
|
Dictionary mapping sortable names to new orders |
required |
Source code in src/pyetm/models/sortables.py
validate_sortables_list
classmethod
Validate the list of sortables
Source code in src/pyetm/models/sortables.py
validate_sortables_consistency
Additional validation for the entire sortables collection
Source code in src/pyetm/models/sortables.py
from_json
classmethod
:param data: the raw JSON dict from GET /api/v3/scenarios/:id/user_sortables
Source code in src/pyetm/models/sortables.py
as_dict
Return a dict mimicking the index endpoint.