Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion elementary/monitor/data_monitoring/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class FilterType(str, Enum):
IS = "is"
IS_NOT = "is_not"
CONTAINS = "contains"
NOT_CONTAINS = "not_contains"


class FilterFields(BaseModel):
Expand All @@ -55,14 +56,16 @@ def apply_filter(filter_type: FilterType, value: Any, filter_value: Any) -> bool
return value != filter_value
elif filter_type == FilterType.CONTAINS:
return str(filter_value).lower() in str(value).lower()
elif filter_type == FilterType.NOT_CONTAINS:
return str(filter_value).lower() not in str(value).lower()
raise ValueError(f"Unsupported filter type: {filter_type}")


ValueT = TypeVar("ValueT")


ANY_OPERATORS = [FilterType.IS, FilterType.CONTAINS]
ALL_OPERATORS = [FilterType.IS_NOT]
ALL_OPERATORS = [FilterType.IS_NOT, FilterType.NOT_CONTAINS]


class FilterSchema(BaseModel, Generic[ValueT]):
Expand Down