<commit_before>from pxl import models
from pxl import serializers
from rest_framework import generics
# from rest_framework.authentication import SessionAuthentication, BasicAuthentication
# from rest_framework.permissions import IsAuthenticated
from rest_framework.permissions import AllowAny
from rest_framework.response import Response
from rest_framework.views import APIView
from django.contrib.auth.models import User
from rest_framework.authtoken.models import Token
from django.http import HttpResponse


class RegisterView(generics.CreateAPIView):
    permission_classes = (AllowAny,)
    serializer_class = serializers.UserSerializer1


class LoginView(APIView):
    """Registration and login view."""
    permission_classes = (AllowAny,)
    serializer_class = serializers.UserLoginSerializer

    def post(self, request, format=None):
        """Return user and authorization to front end."""
        user = User.objects.get(username=request.data['username'])
        if user.password == request.data['password']:
            tok = Token.objects.get(user=user)
            content = {
                'token': str(tok)
            }
        else:
            return HttpResponse('Unauthorized', status=401)
        return Response(content)


class BoardList(generics.ListCreateAPIView, generics.UpdateAPIView):
    permission_classes = (AllowAny,)
    serializer_class = serializers.BoardSerializer
    queryset = models.PXLBoardModel.objects.all()

    # def get_queryset(self):
    #     import pdb; pdb.set_trace()
    #     token = Token.objects.get(key=self.request.data['token'])
    #     user = User.objects.get(username=token.user.username)
    #     return models.PXLBoardModel.objects.get(owner=user)
    #
    # def perform_create(self, serializer):
    #     token = Token.objects.get(key=self.request.data['token'])
    #     user = User.objects.get(username=token.user.username)
    #     serializer.save(owner=user)
    #
    # def perform_update(self, serializer):
    #     token = Token.objects.get(key=self.request.data['token'])
    #     user = User.objects.get(username=token.user.username)
    #     serializer.save(owner=user)<commit_msg>board views get is working, on hiatus at the moment to work on alterning user auth to communicate with front end.<commit_after>from pxl import models
from pxl import serializers
from rest_framework import generics
# from rest_framework.authentication import SessionAuthentication, BasicAuthentication
# from rest_framework.permissions import IsAuthenticated
from rest_framework.permissions import AllowAny
from rest_framework.response import Response
from rest_framework.views import APIView
from django.contrib.auth.models import User
from rest_framework.authtoken.models import Token
from django.http import HttpResponse


class RegisterView(generics.CreateAPIView):
    permission_classes = (AllowAny,)
    serializer_class = serializers.UserSerializer1


class LoginView(APIView):
    """Registration and login view."""
    permission_classes = (AllowAny,)
    serializer_class = serializers.UserLoginSerializer

    def post(self, request, format=None):
        """Return user and authorization to front end."""
        user = User.objects.get(username=request.data['username'])
        if user.password == request.data['password']:
            tok = Token.objects.get(user=user)
            content = {
                'token': str(tok)
            }
        else:
            return HttpResponse('Unauthorized', status=401)
        return Response(content)


class BoardList(generics.ListCreateAPIView, generics.UpdateAPIView):
    permission_classes = (AllowAny,)
    serializer_class = serializers.BoardSerializer
    # queryset = models.PXLBoardModel.objects.all()

    def get_queryset(self):
        import pdb; pdb.set_trace()
        token = Token.objects.get(key=self.request.data['token'])
        user = User.objects.get(username=token.user.username)
        return models.PXLBoardModel.objects.get(owner=user)

    def perform_create(self, serializer):
        import pdb; pdb.set_trace()
        token = Token.objects.get(key=self.request.data['token'])
        user = User.objects.get(username=token.user.username)
        serializer.save(owner=user)

    def perform_update(self, serializer):
        import pdb; pdb.set_trace()
        token = Token.objects.get(key=self.request.data['token'])
        user = User.objects.get(username=token.user.username)
        serializer.save(owner=user)
{'fraction_non_alphanumeric': 0.09759358288770054, 'fraction_numerical': 0.0017825311942959, 'mean_word_length': 3.68580375782881, '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': '5723509', 'n_tokens_mistral': 1242, 'n_tokens_neox': 1210, 'n_words': 273}