Skip to content

Commit fe51215

Browse files
committed
Added support for 'NOT' filter in BaseLux class, including validation for list of conditions. Updated query handling to accommodate 'NOT' alongside existing 'OR' conditions for improved filter functionality.
1 parent 71e36df commit fe51215

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

luxy/api.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,21 @@ def filter(self, **kwargs):
9494
self.filters.append({"OR": value})
9595
continue
9696

97+
# Special handling for NOT conditions
98+
if key == "NOT":
99+
if not isinstance(value, list):
100+
raise ValueError("NOT filter must be a list of conditions")
101+
not_conditions = []
102+
for condition in value:
103+
if isinstance(condition, dict):
104+
not_conditions.append(condition)
105+
else:
106+
not_conditions.append(condition)
107+
self.filters.append({"NOT": not_conditions})
108+
continue
109+
97110
# Rest of the validation logic for regular filters
98-
if key not in valid_options and key not in ["AND", "NOT"]:
111+
if key not in valid_options:
99112
raise ValueError(f"Invalid filter '{key}' for {self.name}. Use list_filters() to see available options.")
100113

101114
# Handle tuple case (value, comparison operator)
@@ -145,9 +158,9 @@ def get(self):
145158
query_ands = []
146159

147160
for filter_dict in self.filters:
148-
# If it's already an OR condition, append as is
149-
if "OR" in filter_dict:
150-
query_ands.append({"OR": filter_dict["OR"]})
161+
# If it's already an OR or NOT condition, append as is
162+
if "OR" in filter_dict or "NOT" in filter_dict:
163+
query_ands.append(filter_dict)
151164
# If it contains both a value and _comp, keep them together
152165
elif "_comp" in filter_dict:
153166
query_ands.append(filter_dict)

0 commit comments

Comments
 (0)