Skip to content

Commit

Permalink
Refactor, cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
terjekv committed Aug 6, 2024
1 parent ec62bbd commit 9253c29
Showing 1 changed file with 0 additions and 27 deletions.
27 changes: 0 additions & 27 deletions mreg/api/v1/filters.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import json
import operator
from functools import reduce
from typing import List
Expand Down Expand Up @@ -34,32 +33,6 @@
EXACT_OPERATORS: OperatorList = ["exact"]


class JSONFieldFilter(filters.CharFilter):
def filter(self, qs, value):
if not value:
return qs

queries = []
for k, v in self.parent.data.items():
if k.startswith("data__"):
json_key = k.split("data__", 1)[1]

if json_key.endswith("__in"):
json_key = json_key[:-4]
try:
values = json.loads(v)
if not isinstance(values, list):
continue
except json.JSONDecodeError:
continue
queries.append(Q(**{f"data__{json_key}__in": values}))
else:
queries.append(Q(**{f"data__{json_key}": v}))

if queries:
return qs.filter(reduce(operator.and_, queries))
return qs


class CIDRFieldExactFilter(filters.CharFilter):
pass
Expand Down

0 comments on commit 9253c29

Please sign in to comment.