Skip to content

update_sortables

update_sortables

Service for updating a 'sortable'

Classes

UpdateSortablesRunner

Bases: BaseRunner[Dict[str, Any]]

Runner for updating a single user sortable on a scenario.

PUT /api/v3/scenarios/{scenario_id}/user_sortables/{sortable_type} PUT /api/v3/scenarios/{scenario_id}/user_sortables/{sortable_type}?subtype={subtype}

Functions
build_request staticmethod
build_request(scenario, sortable_type, order, subtype=None)

Build sortables update request for concurrent batching.

Parameters:

Name Type Description Default
scenario Any

The scenario object (must have an 'id' attribute)

required
sortable_type str

The type of sortable

required
order List[Any]

The new order for the sortable

required
subtype Optional[str]

Optional subtype for heat_network

None

Returns:

Type Description
Dict[str, Any]

Request dict ready for AsyncBatchRunner

Source code in src/pyetm/services/scenario_runners/update_sortables.py
@staticmethod
def build_request(
    scenario: Any, sortable_type: str, order: List[Any], subtype: Optional[str] = None
) -> Dict[str, Any]:
    """
    Build sortables update request for concurrent batching.

    Args:
        scenario: The scenario object (must have an 'id' attribute)
        sortable_type: The type of sortable
        order: The new order for the sortable
        subtype: Optional subtype for heat_network

    Returns:
        Request dict ready for AsyncBatchRunner
    """
    path = f"/scenarios/{scenario.id}/user_sortables/{sortable_type}"
    if subtype:
        path += f"?subtype={subtype}"

    return {
        "method": "put",
        "path": path,
        "payload": {"order": order},
        "kwargs": {},
    }
run staticmethod
run(client, scenario, sortable_type, order, subtype=None, **kwargs)

Update a single sortable for a scenario - the endpoint doesn't handle bulk updates.

Parameters:

Name Type Description Default
client BaseClient

The HTTP client to use

required
scenario Any

The scenario object (must have an 'id' attribute)

required
sortable_type str

The type of sortable (e.g., "demand", "heat_network")

required
order List[Any]

The new order for the sortable

required
subtype Optional[str]

Optional subtype for heat_network (e.g., "lt", "mt", "ht")

None
**kwargs Any

Additional arguments passed to the request

{}
Source code in src/pyetm/services/scenario_runners/update_sortables.py
@staticmethod
def run(
    client: BaseClient,
    scenario: Any,
    sortable_type: str,
    order: List[Any],
    subtype: Optional[str] = None,
    **kwargs: Any,
) -> ServiceResult[Dict[str, Any]]:
    """
    Update a single sortable for a scenario - the endpoint doesn't handle bulk updates.

    Args:
        client: The HTTP client to use
        scenario: The scenario object (must have an 'id' attribute)
        sortable_type: The type of sortable (e.g., "demand", "heat_network")
        order: The new order for the sortable
        subtype: Optional subtype for heat_network (e.g., "lt", "mt", "ht")
        **kwargs: Additional arguments passed to the request
    """
    path = f"/scenarios/{scenario.id}/user_sortables/{sortable_type}"
    if subtype:
        path += f"?subtype={subtype}"

    payload = {"order": order}

    return UpdateSortablesRunner._make_request(
        client=client,
        method="put",
        path=path,
        payload=payload,
    )