<commit_before>from rest_framework import viewsets
from rest_framework.response import Response

from farm.models import Owner, Location, GroupType, Group, Node, PackageType, Package, PackageCheck
from farm.serializers import OwnerSerializer, LocationSerializer, GroupTypeSerializer, GroupSerializer, NodeSerializer, PackageTypeSerializer, PackageSerializer, PackageCheckSerializer


class OwnerViewSet(viewsets.ModelViewSet):
    queryset = Owner.objects.all()
    serializer_class = OwnerSerializer


class LocationViewSet(viewsets.ModelViewSet):
    queryset = Location.objects.all()
    serializer_class = LocationSerializer


class GroupTypeViewSet(viewsets.ModelViewSet):
    queryset = GroupType.objects.all()
    serializer_class = GroupTypeSerializer

    def create(self, request, *args, **kwargs):
        import pdb; pdb.set_trace()
        data = request.DATA #JSONParser().parse(request)
        queryset = GroupType.objects.all()
        serializer = GroupTypeSerializer(data=data, many=True)

        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data, status=201)
        else:
            return Response(serializer.errors, status=400)


class GroupViewSet(viewsets.ModelViewSet):
    queryset = Group.objects.all()
    serializer_class = GroupSerializer


class NodeViewSet(viewsets.ModelViewSet):
    serializer_class = NodeSerializer
    queryset = Node.objects.all()
    lookup_field = 'slug'


class PackageTypeViewSet(viewsets.ModelViewSet):
    queryset = PackageType.objects.all()
    serializer_class = PackageTypeSerializer


class PackageCheckViewSet(viewsets.ModelViewSet):
    serializer_class = PackageCheckSerializer
    queryset = PackageCheck.objects.all()<commit_msg>created BulkModelViewSet with create and put methods, changed GroupTypeViewSet to use it<commit_after>from rest_framework import viewsets, status
from rest_framework.response import Response

from farm.models import Owner, Location, GroupType, Group, Node, PackageType, Package, PackageCheck
from farm.serializers import OwnerSerializer, LocationSerializer, GroupTypeSerializer, GroupSerializer, NodeSerializer, PackageTypeSerializer, PackageSerializer, PackageCheckSerializer


class BulkModelViewSet(viewsets.ModelViewSet):
    
    
    def create(self, request, *args, **kwargs):
        import pdb; pdb.set_trace()
        data = request.DATA #JSONParser().parse(request)
        serializer = GroupTypeSerializer(data=data, many=True)

        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        else:
            return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)


    def put(self, request, *args, **kwargs):
        import pdb; pdb.set_trace()
        data = request.DATA #JSONParser().parse(request)
        queryset = GroupType.objects.all()
        serializer = GroupTypeSerializer(queryset, data=data, many=True)

        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        else:
            return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)


class OwnerViewSet(viewsets.ModelViewSet):
    queryset = Owner.objects.all()
    serializer_class = OwnerSerializer


class LocationViewSet(viewsets.ModelViewSet):
    queryset = Location.objects.all()
    serializer_class = LocationSerializer


class GroupTypeViewSet(BulkModelViewSet):
    queryset = GroupType.objects.all()
    serializer_class = GroupTypeSerializer


class GroupViewSet(viewsets.ModelViewSet):
    queryset = Group.objects.all()
    serializer_class = GroupSerializer


class NodeViewSet(viewsets.ModelViewSet):
    serializer_class = NodeSerializer
    queryset = Node.objects.all()
    lookup_field = 'slug'


class PackageTypeViewSet(viewsets.ModelViewSet):
    queryset = PackageType.objects.all()
    serializer_class = PackageTypeSerializer


class PackageCheckViewSet(viewsets.ModelViewSet):
    serializer_class = PackageCheckSerializer
    queryset = PackageCheck.objects.all()
{'fraction_non_alphanumeric': 0.08244680851063829, 'fraction_numerical': 0.004352030947775629, 'mean_word_length': 4.324324324324325, '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': '6182201', 'n_tokens_mistral': 1144, 'n_tokens_neox': 1102, 'n_words': 238}