<commit_before>from rest_framework.generics import GenericAPIView
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework import status

from sloop.serializers import HelloSerializer


class BaseHelloView(GenericAPIView):
    """
    An endpoint for retrieving Facebook access token and push token
    """
    serializer_class = HelloSerializer
    permission_classes = (IsAuthenticated,)

    def post(self, request, *args, **kwargs):
        serializer = self.get_serializer(data=request.DATA, files=request.FILES, partial=True)
        if serializer.is_valid():
            # Create push token object if necessary
            push_token, created = self.model.objects.get_or_create(
                token=serializer.data.get("push_token"),
                device_type=serializer.data.get("device_type"),
                defaults={
                    "profile": request.user,
                    "locale": serializer.data.get("locale"),
                }
            )
            if push_token.profile_id != request.user.id:
                push_token.profile = request.user
            push_token.save()
            return Response(serializer.data, status=status.HTTP_200_OK)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

<commit_msg>remove request.FILES to support both DRF 2 and 3<commit_after>from rest_framework.generics import GenericAPIView
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework import status

from sloop.serializers import HelloSerializer


class BaseHelloView(GenericAPIView):
    """
    An endpoint for retrieving Facebook access token and push token
    """
    serializer_class = HelloSerializer
    permission_classes = (IsAuthenticated,)

    def post(self, request, *args, **kwargs):
        serializer = self.get_serializer(data=request.DATA)
        if serializer.is_valid():
            # Create push token object if necessary
            push_token, created = self.model.objects.get_or_create(
                token=serializer.data.get("push_token"),
                device_type=serializer.data.get("device_type"),
                defaults={
                    "profile": request.user,
                    "locale": serializer.data.get("locale"),
                }
            )
            if push_token.profile_id != request.user.id:
                push_token.profile = request.user
            push_token.save()
            return Response(serializer.data, status=status.HTTP_200_OK)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)


{'fraction_non_alphanumeric': 0.0815868263473054, 'fraction_numerical': 0.005239520958083832, 'mean_word_length': 2.686896551724138, 'pattern_counts': {'":': 4, '<': 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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2524024', 'n_tokens_mistral': 708, 'n_tokens_neox': 672, 'n_words': 156}