<commit_before>import datetime
import uuid
import json
from django.utils import timezone
from django.http import HttpResponse
from django.shortcuts import render
from .models import Move, Spot
from rest_framework import viewsets
from rest_framework import status
from rest_framework.decorators import list_route
from rest_framework.views import APIView
from rest_framework.response import Response
from .serializers import MoveSerializer, SpotSerializer
from django.utils.decorators import method_decorator
from django.views.decorators.csrf import ensure_csrf_cookie

@ensure_csrf_cookie
def index(request):

    user_uuid = request.session.get('user_uuid') or str(uuid.uuid4())
    request.session['user_uuid'] = user_uuid
    request.session.set_expiry(None)

    move = Move.objects.filter(uuid=user_uuid).order_by('-time').first()
    if move and move.time >= timezone.now() - datetime.timedelta(hours=6):
        move = MoveSerializer(move).data
    elif move:
        move = {'user': move.user}
    else:
        move = {}

    return render(request, 'moves/index.html', {'recent_move': json.dumps(move)})

class MoveViewSet(viewsets.ModelViewSet):
    queryset = Move.objects.recent()
    serializer_class = MoveSerializer

    def perform_create(self, serializer):
        serializer.save()

    def create(self, request):
        data = request.data.copy()
        data.update({'uuid': request.session['user_uuid']})
        serializer = self.get_serializer(data=data)
        serializer.is_valid(raise_exception=True)
        self.perform_create(serializer)
        headers = self.get_success_headers(serializer.data)
        return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers)


class SpotViewSet(viewsets.ModelViewSet):
    queryset = Spot.objects.all()
    serializer_class = SpotSerializer<commit_msg>lets not override perform_create, its a silly place<commit_after>import datetime
import uuid
import json
from django.utils import timezone
from django.http import HttpResponse
from django.shortcuts import render
from .models import Move, Spot
from rest_framework import viewsets
from rest_framework import status
from rest_framework.decorators import list_route
from rest_framework.views import APIView
from rest_framework.response import Response
from .serializers import MoveSerializer, SpotSerializer
from django.utils.decorators import method_decorator
from django.views.decorators.csrf import ensure_csrf_cookie

@ensure_csrf_cookie
def index(request):

    user_uuid = request.session.get('user_uuid') or str(uuid.uuid4())
    request.session['user_uuid'] = user_uuid
    request.session.set_expiry(None)

    move = Move.objects.filter(uuid=user_uuid).order_by('-time').first()
    if move and move.time >= timezone.now() - datetime.timedelta(hours=6):
        move = MoveSerializer(move).data
    elif move:
        move = {'user': move.user}
    else:
        move = {}

    return render(request, 'moves/index.html', {'recent_move': json.dumps(move)})

class MoveViewSet(viewsets.ModelViewSet):
    queryset = Move.objects.recent()
    serializer_class = MoveSerializer

    def create(self, request):
        data = request.data.copy()
        data.update({'uuid': request.session['user_uuid']})
        serializer = self.get_serializer(data=data)
        serializer.is_valid(raise_exception=True)
        self.perform_create(serializer)
        headers = self.get_success_headers(serializer.data)
        return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers)


class SpotViewSet(viewsets.ModelViewSet):
    queryset = Spot.objects.all()
    serializer_class = SpotSerializer
{'fraction_non_alphanumeric': 0.09510795299262094, 'fraction_numerical': 0.002732987154960372, 'mean_word_length': 4.462686567164179, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '6386318', 'n_tokens_mistral': 1063, 'n_tokens_neox': 1037, 'n_words': 244}