From 9253c29c884b4eca5405d2b4f2dcf3d0f8bb0623 Mon Sep 17 00:00:00 2001 From: Terje Kvernes Date: Tue, 6 Aug 2024 23:30:45 +0200 Subject: [PATCH] Refactor, cleanup. --- mreg/api/v1/filters.py | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/mreg/api/v1/filters.py b/mreg/api/v1/filters.py index c5008797..ba88b9cc 100644 --- a/mreg/api/v1/filters.py +++ b/mreg/api/v1/filters.py @@ -1,4 +1,3 @@ -import json import operator from functools import reduce from typing import List @@ -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