<commit_before>from rest_framework import viewsets

from paranuara_api.models import Company, Person
from paranuara_api.serializers import (
        CompanySerializer, CompanyListSerializer, PersonListSerializer,
        PersonSerializer
)

class CompanyViewSet(viewsets.ReadOnlyModelViewSet):
    queryset = Company.objects.all()
    lookup_field = 'index'

    serializers = {
        'list': CompanyListSerializer,
        'retrieve': CompanySerializer,
    }

    def get_serializer_class(self):
        return self.serializers[self.action]


class PersonViewSet(viewsets.ReadOnlyModelViewSet):
    queryset = Person.objects.all()
    lookup_field = 'index'

    serializers = {
        'list': PersonListSerializer,
        'retrieve': PersonSerializer,
    }

    def get_serializer_class(self):
        return self.serializers[self.action]
<commit_msg>Refactor common serializer selection code.<commit_after>from rest_framework import viewsets

from paranuara_api.models import Company, Person
from paranuara_api.serializers import (
        CompanySerializer, CompanyListSerializer, PersonListSerializer,
        PersonSerializer
)

class MultiSerializerMixin(object):

    def get_serializer_class(self):
        return self.serializers[self.action]


class CompanyViewSet(MultiSerializerMixin, viewsets.ReadOnlyModelViewSet):
    queryset = Company.objects.all()
    lookup_field = 'index'

    serializers = {
        'list': CompanyListSerializer,
        'retrieve': CompanySerializer,
    }


class PersonViewSet(MultiSerializerMixin, viewsets.ReadOnlyModelViewSet):
    queryset = Person.objects.all()
    lookup_field = 'index'

    serializers = {
        'list': PersonListSerializer,
        'retrieve': PersonSerializer,
    }

{'fraction_non_alphanumeric': 0.08070978820835718, 'fraction_numerical': 0.0, 'mean_word_length': 3.896358543417367, 'pattern_counts': {'":': 0, '<': 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': '2188962', 'n_tokens_mistral': 483, 'n_tokens_neox': 472, 'n_words': 96}