<commit_before>from rest_framework import viewsets
from rest_framework import filters

from .models import Poll, Answer
from .serializers import PollSerializer, AnswerSerializer

from rest_framework.permissions import IsAdminUser
from bulbs.api.views import ContentViewSet
from bulbs.api.permissions import CanEditContent

class PollViewSet(viewsets.ModelViewSet):
    model = Poll
    queryset = Poll.objects.all()
    permission_classes = [
        IsAdminUser,
        CanEditContent,
    ]
    serializer_class = PollSerializer
    paginate_by = 20
    filter_backends = (
            filters.OrderingFilter,
            filters.SearchFilter,)
    ordering_fields = (
            "title",
            "published",
            "end_date",)
    search_fields = (
            "answers",
            "title",)

class AnswerViewSet(viewsets.ModelViewSet):
    model = Answer
    queryset = Answer.objects.all()
    permission_classes = [
        IsAdminUser,
        CanEditContent,
    ]
    serializer_class = AnswerSerializer<commit_msg>search restored for poll listing<commit_after>from rest_framework import viewsets
from rest_framework import filters

from .models import Poll, Answer
from .serializers import PollSerializer, AnswerSerializer

from rest_framework.permissions import IsAdminUser
from rest_framework.response import Response

from bulbs.api.views import ContentViewSet
from bulbs.api.permissions import CanEditContent
from bulbs.utils.methods import get_query_params, get_request_data

class PollViewSet(viewsets.ModelViewSet):
    model = Poll
    queryset = Poll.objects.all()
    permission_classes = [
        IsAdminUser,
        CanEditContent,
    ]
    serializer_class = PollSerializer
    paginate_by = 20
    filter_backends = (
            filters.OrderingFilter,
            filters.SearchFilter,)
    ordering_fields = (
            "title",
            "published",
            "end_date",)
    search_fields = (
            "answers",
            "title",)

    def list(self, request, *args, **kwargs):
        """Modified list view to driving listing from ES"""
        search_kwargs = {"published": False}

        for field_name in ("before", "after", "status", "published"):

            if field_name in get_query_params(self.request):
                search_kwargs[field_name] = get_query_params(self.request).get(field_name)

        if "search" in get_query_params(self.request):
            search_kwargs["query"] = get_query_params(self.request).get("search")

        queryset = self.model.search_objects.search(**search_kwargs)

        page = self.paginate_queryset(queryset)
        if page is not None:
            serializer = self.get_serializer(page, many=True)
            return self.get_paginated_response(serializer.data)

        serializer = self.get_serializer(queryset, many=True)
        return Response(serializer.data)

class AnswerViewSet(viewsets.ModelViewSet):
    model = Answer
    queryset = Answer.objects.all()
    permission_classes = [
        IsAdminUser,
        CanEditContent,
    ]
    serializer_class = AnswerSerializer
{'fraction_non_alphanumeric': 0.08027079303675048, 'fraction_numerical': 0.0012894906511927789, 'mean_word_length': 2.9428208386277, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3789827', 'n_tokens_mistral': 853, 'n_tokens_neox': 831, 'n_words': 194}