Skip to content

omni.OmniFilterSet

Helper class for generating a set of filter search parameters for an embedded dashboard. This class is designed to abstract the complexity of the Omni filters and create a simple interface for generating the filter values to be used by the OmniEmbedder.

Parameters:

Name Type Description Default
**filters OmniFilterDefinition

Arbitrary kwargs defining filter definitions. The kwarg is the name of the filter and defines the schema for the dict that should be passed to the get_filter_search_params method. The value for each kwarg is the OmniFilterDefinition object that will be used to translate the value to a viable Omni filter search param.

{}
Source code in src/omni/embed.py
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
class OmniFilterSet:
    """Helper class for generating a set of filter search parameters for an embedded dashboard. This class is designed
    to abstract the complexity of the Omni filters and create a simple interface for generating the filter values to
    be used by the OmniEmbedder.

    Args:
        **filters: Arbitrary kwargs defining filter definitions. The kwarg is the name of the filter and defines the
            schema for the dict that should be passed to the get_filter_search_params method. The value for each kwarg is
            the OmniFilterDefinition object that will be used to translate the value to a viable Omni filter search param.

    """

    def __init__(self, **filters: OmniFilterDefinition) -> None:
        for value in filters.values():
            if not isinstance(value, OmniFilterDefinition):
                raise TypeError("Filters must be an OmniFilterDefinition object.")
        self._filters = filters

    @property
    def filters(self) -> dict[str, OmniFilterDefinition]:
        """Filters in this filter set. This defines the schema of the dict that should be passed to the
        `get_filter_search_params` method.
        """
        # Using a property function here to discourage manipulating filters after instantiation.
        return self._filters

    def get_filter_search_params(
        self, filter_values: dict[str, str | int | float]
    ) -> dict[str, list[str]]:
        """Given a dictionary of filter keys and values this function returns the dictionary of expected to populate
        the filter_search_params kwarg when calling OmniEmbedder.build_url. This method is ideal for
        translating query params in the encapsulating application to Omni filter search parameters.

        Args:
            filter_values: Dict where the keys are the filter names and values are the values to filter on. The
                list of available filters can be found in the `filters` property.

        Returns:
            : Dict to be passed as the `filter_search_params` kwarg in the `OmniEmbedder.build_url` method.
        """
        filter_search_params = {}
        for query_param, value in filter_values.items():
            omni_filter = self.filters[query_param]
            filter_key, filter_value = omni_filter.get_filter_search_param_info(value)
            filter_search_params[filter_key] = filter_value
        return filter_search_params

filters property

Filters in this filter set. This defines the schema of the dict that should be passed to the get_filter_search_params method.

get_filter_search_params(filter_values)

Given a dictionary of filter keys and values this function returns the dictionary of expected to populate the filter_search_params kwarg when calling OmniEmbedder.build_url. This method is ideal for translating query params in the encapsulating application to Omni filter search parameters.

Parameters:

Name Type Description Default
filter_values dict[str, str | int | float]

Dict where the keys are the filter names and values are the values to filter on. The list of available filters can be found in the filters property.

required

Returns:

Type Description
dict[str, list[str]]

Dict to be passed as the filter_search_params kwarg in the OmniEmbedder.build_url method.

Source code in src/omni/embed.py
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
def get_filter_search_params(
    self, filter_values: dict[str, str | int | float]
) -> dict[str, list[str]]:
    """Given a dictionary of filter keys and values this function returns the dictionary of expected to populate
    the filter_search_params kwarg when calling OmniEmbedder.build_url. This method is ideal for
    translating query params in the encapsulating application to Omni filter search parameters.

    Args:
        filter_values: Dict where the keys are the filter names and values are the values to filter on. The
            list of available filters can be found in the `filters` property.

    Returns:
        : Dict to be passed as the `filter_search_params` kwarg in the `OmniEmbedder.build_url` method.
    """
    filter_search_params = {}
    for query_param, value in filter_values.items():
        omni_filter = self.filters[query_param]
        filter_key, filter_value = omni_filter.get_filter_search_param_info(value)
        filter_search_params[filter_key] = filter_value
    return filter_search_params