From 1cdcc7970488210f1712e3081cc082dd78d45b53 Mon Sep 17 00:00:00 2001 From: juuso-j Date: Mon, 17 Jul 2023 14:48:16 +0300 Subject: [PATCH] Remove obsolete elasticsearch related code --- services/api.py | 56 ------------------------------------------------- 1 file changed, 56 deletions(-) diff --git a/services/api.py b/services/api.py index d37244eba..4c232c751 100644 --- a/services/api.py +++ b/services/api.py @@ -51,8 +51,6 @@ else: DEFAULT_RENDERERS = () -# This allows us to find a serializer for Haystack search results -serializers_by_model = {} all_views = [] @@ -63,14 +61,6 @@ def register_view(klass, name, basename=None): entry["basename"] = basename all_views.append(entry) - if ( - klass.serializer_class - and hasattr(klass.serializer_class, "Meta") - and hasattr(klass.serializer_class.Meta, "model") - ): - model = klass.serializer_class.Meta.model - serializers_by_model[model] = klass.serializer_class - LANGUAGES = [x[0] for x in settings.LANGUAGES] @@ -1085,52 +1075,6 @@ def list(self, request, **kwargs): register_view(UnitViewSet, "unit") -class SearchSerializer(serializers.Serializer): - def __init__(self, *args, **kwargs): - super(SearchSerializer, self).__init__(*args, **kwargs) - self.serializer_by_model = {} - - def _strip_context(self, context, model): - if model == Unit: - key = "unit" - elif model == Service: - key = "service" - else: - key = "service_node" - for spec in ["include", "only"]: - if spec in context: - context[spec] = context[spec].get(key, []) - if "only" in context and context["only"] == []: - context.pop("only") - return context - - def get_result_serializer(self, model, instance): - ser = self.serializer_by_model.get(model) - if not ser: - ser_class = serializers_by_model[model] - assert model in serializers_by_model, "Serializer for %s not found" % model - context = self._strip_context(self.context.copy(), model) - ser = ser_class(context=context, many=False) - self.serializer_by_model[model] = ser - # TODO: another way to serialize with new data without - # costly Serializer instantiation - ser.instance = instance - if hasattr(ser, "_data"): - del ser._data - return ser - - def to_representation(self, search_result): - if not search_result or not search_result.model: - return None - model = search_result.model - serializer = self.get_result_serializer(model, search_result.object) - data = serializer.data - data["sort_index"] = search_result._sort_index - data["object_type"] = model._meta.model_name - data["score"] = search_result.score - return data - - class AccessibilityRuleView(viewsets.ViewSetMixin, generics.ListAPIView): serializer_class = None