Skip to content

Record Views

record_views

Module for managing Kaleidoscope record views and their operations.

This module provides classes and services for interacting with record views in the Kaleidoscope system.

Classes:

Name Description
RecordTransfer

TypedDict defining the structure for transferring records with key field values.

ViewField

TypedDict defining the structure for view fields with data and lookup field references.

RecordView

Model representing a record view with methods for extending views.

RecordViewsService

Service class for managing record view operations and API interactions.

Example
    views = client.record_views.get_record_views()
    for view in views:
        print(f"View: {view.view_name}, Entity Slice: {view.entity_slice_id}")

    # View: Customer Records, Entity Slice: abc-123-def
    # View: Product Catalog, Entity Slice: xyz-456-ghi

RecordTransfer

Bases: TypedDict

TypedDict defining the structure for transferring records with key field values.

Attributes:

Name Type Description
record_id str

The unique identifier of the record to transfer.

key_field_name_to_value dict[str, Any]

A dictionary mapping key field names to their values.

ViewField

Bases: TypedDict

TypedDict defining the structure for view fields with data and lookup field references.

Attributes:

Name Type Description
data_field_id str | None

The ID of the data field, if applicable.

lookup_field_id str | None

The ID of the lookup field, if applicable.

RecordView

Bases: _KaleidoscopeBaseModel

Represents a view of records in the Kaleidoscope system.

A RecordView defines how records are displayed and accessed, including the entity slice they belong to, associated programs and operations, and the fields visible in the view.

Attributes:

Name Type Description
id str

UUID of the record view

entity_slice_id str

ID of the entity slice this view belongs to.

program_ids list[str]

List of program IDs associated with this view. Defaults to empty list.

operation_ids list[str] | None

Optional list of operation IDs associated with this view.

operation_definition_ids list[str] | None

Optional list of operation definition IDs.

view_fields list[ViewField]

List of fields visible in this view. Defaults to empty list.

Classes:

Name Description
ExtendViewBody

TypedDict defining the body for extending a record view.

Methods:

Name Description
extend_view

Extends the current record view by adding a key field.

ExtendViewBody

Bases: TypedDict

TypedDict defining the body for extending a record view.

Attributes:

Name Type Description
new_key_field_name str

The name of the new key field to add.

records_to_transfer list[RecordTransfer] | None

A list of records to transfer with their new key values.

extend_view

extend_view(body: ExtendViewBody) -> None

Extends the current record view by adding a key field.

Parameters:

Name Type Description Default
body ExtendViewBody

The request body containing information about the key field to add.

required
Source code in kalpy/record_views.py
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
def extend_view(self, body: ExtendViewBody) -> None:
    """Extends the current record view by adding a key field.

    Args:
        body (ExtendViewBody): The request body containing information about the key field to add.
    """
    try:
        resp = self._client._put(
            "/record_views/" + self.id + "/add_key_field", dict(body)
        )
        if resp:
            for key, value in resp.items():
                if hasattr(self, key):
                    setattr(self, key, value)
    except Exception as e:
        _logger.error(f"Error updating record view: {e}")
        return None

RecordViewsService

RecordViewsService(client: KaleidoscopeClient)

Service class for managing record views in Kaleidoscope.

This service provides methods to interact with record views, including retrieving, creating, and managing RecordView objects. It handles the conversion of raw data into RecordView instances and ensures proper client association.

Example
views = client.record_views.get_record_views()
for view in views:
    print(f"View: {view.view_name}, Entity Slice: {view.entity_slice_id}")

# View: Customer Records, Entity Slice: abc-123-def
# View: Product Catalog, Entity Slice: xyz-456-ghi

Methods:

Name Description
get_record_views

Retrieves a list of record views available in the workspace.

Source code in kalpy/record_views.py
129
130
def __init__(self, client: KaleidoscopeClient):
    self._client = client

get_record_views cached

get_record_views() -> list[RecordView]

Retrieves a list of record views available in the workspace.

This method caches its values.

Returns:

Type Description
list[RecordView]

List[RecordView]: A list of RecordView objects representing the record views in the workspace.

Note

If an exception occurs during the API request, it logs the error, clears the cache, and returns an empty list.

Source code in kalpy/record_views.py
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
@lru_cache
def get_record_views(self) -> List[RecordView]:
    """Retrieves a list of record views available in the workspace.

    This method caches its values.

    Returns:
        List[RecordView]: A list of RecordView objects representing the record views in the workspace.

    Note:
        If an exception occurs during the API request, it logs the error,
        clears the cache, and returns an empty list.
    """
    try:
        resp = self._client._get("/record_views")
        return self._create_record_views_list(resp)
    except Exception as e:
        _logger.error(f"Error fetching record views: {e}")
        self.get_record_views.cache_clear()
        return []